Common Docker basic commands and usage summary
- 2020-05-24 06:28:38
- OfStack
View the docker installation information
docker info
Get the docker image
docker pull azraelrabbit/monupw
Create the docker container
docker run --name monojexus -d -p 32022:22 -p 32080:80 -v /mydata:/data azraelrabbit/monupw
Run the docker container as a back-end process
sample_job=$(docker run -d monojexus /bin/sh -c "while true; do echo Docker; sleep 1; done")
Use the docker logs command to view the current state of job
docker logs $sample_job
View docker common commands using docker help
docker help
Stop the background container for sample_job
docker top $sample_job
Use the command to restart the background container
docker restart $sample_job
Stop and remove the container
docker top $sample_job docker rm $sample_job
Save the container state as an image
docker commit $sample_job job1.1
View the image that the machine already has
docker pull azraelrabbit/monupw
0
The mirror to find
docker search <image-namge>
View the historical version of the mirror
docker history <image-name>
Push the mirror to the mirror repository
docker push <image-name>
The format of the library name
<user>/</image_name>
View the version number of docker, including client, server, dependent Go, and so on
docker version
By default, container is running
docker ps
Displays the container that was created the last time, including the ones that were not run
docker ps �l
Displays all container, including unrun ones
docker ps �a
View the log of container, which is the output of executing the command
docker logs <container>
Delete 1 or more container
docker rm <container...>
Delete all container
docker rm `docker ps -a -q`
Delete all container
docker ps -a -q | xargs docker rm
Delete 1 or more image
docker rmi <image...>
Start/stop/restart container
docker start/stop/restart <container>
Start one container and enter interactive mode
docker start -i <container>
attach1 running container
docker attach <container>
Use image to create container, execute the appropriate command, and then stop
docker run <image> <command>
Use image to create container and enter interactive mode. login shell is /bin/bash
docker run -i -t <image> /bin/bash
Map the port of container to the port of the host
docker run -i -t -p <host_port:contain_port>
Solidify 1 container into a new image, repo:tag is optional
sample_job=$(docker run -d monojexus /bin/sh -c "while true; do echo Docker; sleep 1; done")
0
Look for the Dockerfile configuration file named under the path path and use this configuration to generate a new image
sample_job=$(docker run -d monojexus /bin/sh -c "while true; do echo Docker; sleep 1; done")
1
As above, you can specify repo and the optional tag
sample_job=$(docker run -d monojexus /bin/sh -c "while true; do echo Docker; sleep 1; done")
2
Using the specified dockerfile configuration file, docker gets the content as stdin, and a new image is generated using this configuration
docker build - < <dockerfile>
To see which port locally maps to the specified port of container, you can also see it with docker ps
docker port <container> <container port>
Change hostname
#docker run -it --hostname web jim/custom1 /bin/bash