Docker usage skills and common commands, docker usage skills
Install docker
Check whether the curl package is installed?
which curl
If curl is not installed, update the apt source first and install curl as follows:
apt-get updateapt-get install curlapt-get updatewget -qO- https://get.docker.com/ | sh
Set the current user as the docker user group, which is convenient to solve the need to enter a password every time the docker command is executed.
# Add a new docker user group groupadd docker # Add the current user to the docker user group. Note that xxoo here is the ubuntu server login user name gpasswd -a xxoo docker # Restart the docker background monitoring process service docker restart # After restart, try it , Whether it takes effect docker version # If it has not yet taken effect, the system restarts, then takes effect reboot
Start the docker service as follows:
service docker start
Common commands
Run container
docker run hello-world
Show local mirror
docker images
Get mirror
docker pull ubuntu: 12.04
Create a container and let it run bash
docker run -t -i ubuntu: 12.04 / bin / sh
Explanation: -i: means to run the container in "interactive mode" -t: means that the container will enter its command line after starting.
docker ps -adocker save -o ubuntu.tar.gz ubuntu: 14.04 * (Save the version record of all this image, including some historical data.) * docker export pid> ./ubuntu.tar.gz * (Export is (The image content currently used by the container) *
Import container
docker stop xxx docker rm xxx
Note: docker files are placed in / var / lib / docker / containers /.
Save image
docker commit xxx abc
Note: This is saved as a mirror named abc. Only lower case letters and numbers are allowed in the mirror name.
Delete mirror
docker rmi abc
Get mirror history
docker history abcdocker images --tree * (view the history of all images) *
Note: This command can only be executed on a locally existing docker image.
Kill one or more specified container processes
docker kill container
Description: -s "KILL" customizes the signal sent to the container.
View a running container process
docker top container
Note: ps command parameters are also supported.
Suspend all processes in a container
docker pause container
Resume all processes of a container
docker unpause container
Mark a local mirror and put it in a warehouse
docker tag image name
Explanation: -f overwrites the existing mark.
Get the output log of the container runtime
docker logs container
docker attach
docker run -itd ubuntu: 14.04 / bin / bashdocker attach 44fc0f0582d9
Note: docker attach can attach to the stdin of an already running container, and then perform the command execution action. However, it should be noted that if you exit from this stdin, it will cause the container to stop.
docker exec
docker exec -i name / bin / sh
When only -i is used, since there is no pseudo terminal assigned, it looks like pipe execution. But the execution result and command return value can be obtained correctly.
docker exec -it name / bin / sh
When using -it, it is similar to our usual console interface. And it will not cause the entire container to withdraw due to the attachment method.
docker exec -t name / bin / sh
If you only use the -t parameter, you can see a console window, but when you execute the command, you will find that you cannot see the execution of the command because you don't get the output of stdin.
docker exec -d name / bin / sh a.sh
Perform a process in the background. It can be seen that if a command takes a long time to process, the -d parameter will return quickly. The program runs in the background.
Hierarchical display of information for an image or container
docker inspect 465c60612e5c
Common container installation
mysql
docker search mysql
docker pull mysql
docker run --name xmysql-db -e MYSQL_ROOT_PASSWORD = root -d -p 3306: 3306 -v / data / mysql_data /: / var / lib / mysql mysql
mongodb
docker pull mongo
docker run --name xmongo-db -p 27018: 27017 -v / data / my_mongo_data: / data / db -d mongo
jenkins
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.