Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the necessary Docker commands for developers?

Shulou Source: shulou.com Published: 2022-06-01 08:51:05 09月30日 Update

Editor to share with you what Docker commands developers must have. I hope you will gain something after reading this article. Let's discuss it together.

Introduction to Docker

Docker is an open source application container engine that allows developers to package their applications and dependencies into a portable image and publish them to any popular Linux or Windows machine. Using Docker makes it easier to package, test, and deploy applications at a low level.

Docker environment installation

1. Install yum-utils:

Yum install-y yum-utils device-mapper-persistent-data lvm2

two。 Add the docker warehouse location for the yum source:

Yum-config-manager-- add-repo https://download.docker.com/linux/centos/docker-ce.repo

3. Install docker:

Yum install docker-ce

4. Start docker:

Common commands for systemctl start dockerDocker images search for image docker search java

Download image docker pull java:8 how to find the supported version of the image

Since the docker search command can only find out whether the image exists, but cannot find the supported version of the image, we need to search for the supported version through docker hub.

Go to docker hub's official website at https://hub.docker.com

Then search for the desired image:

View the versions supported by the image:

Download the image:

Docker pull nginx:1.17.0 lists mirrored docker images

Delete Mirror

Specify a name to delete the mirror

Docker rmi java:8

Specify name to delete mirror (mandatory)

Docker rmi-f java:8

Force deletion of all mirrors

Docker rmi-f $(docker images) Docker Container Common commands New and start Container docker run-p 80:80-- name nginx-d nginx:1.17.0

-d option: indicates running in the background

-- name option: specify the name of the container after running as nginx, and then you can manipulate the container by name.

-p option: specify port mapping, format: hostPort:containerPort

List containers

List the containers that are running:

Docker ps

List all containers

Docker ps-a

Stop containers # $ContainerName and $ContainerId can be queried docker stop $ContainerName (or $ContainerId) with the docker ps command

For example:

Docker stop nginx # or docker stop c5f5d5125587 force stop container docker kill $ContainerName (or $ContainerId) start the stopped container docker start $ContainerName (or $ContainerId) to enter the container

First query the pid of the container:

Docker inspect-- format "{{.State.Pid}" $ContainerName (or $ContainerId)

Enter the container according to its pid:

Nsenter-target "$pid"-mount-uts-ipc-net-pid

Delete Container

Delete the specified container:

Docker rm $ContainerName (or $ContainerId)

Force deletion of all containers

Docker rm-f $(docker ps-a-Q) View the container log docker logs $ContainerName (or $ContainerId)

Check the IP address of the container, docker logs $ContainerName (or $ContainerId)

Synchronize the host time to the container docker cp / etc/localtime $ContainerName (or $ContainerId): / etc/ check the use of cpu, memory, network and io of docker in the host.

View the specified container:

Docker stats $ContainerName (or $ContainerId)

View all containers:

Docker stats-a

Enter the bashdocker exec-it $ContainerName / bin/bash inside the Docker container

Modify the location of the Docker image

View the location where the Docker image is stored:

Docker info | grep "Docker Root Dir"

Shut down the Docker service:

Systemctl stop docker

Move the directory to the destination path:

Mv / var/lib/docker / mydata/docker

Establish a soft connection:

Ln-s / mydata/docker / var/lib/docker

After reading this article, I believe you have a certain understanding of "what are the necessary Docker commands for developers". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Container image command version enforcement support developer development location situation application search run name address host host commonly used article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Redmi macOS Shulou Technology Huawei