Docker technology and its use

【Docker technology and its use】basic concept

Docker image (image)
A Docker image is a read-only template. Images can be used to create Docker containers. Docker provides a very simple mechanism to create an image or update an existing image, and users can even download a ready-made image directly from others to use directly
Docker container (container)
Docker uses containers to run applications. A container is a running instance created from an image. It can be started, started, stopped, deleted. Each container is isolated from each other, ensuring a secure platform.
Docker repository (repository)
A warehouse is a place where image files are stored centrally. Sometimes the warehouse and the warehouse registry server ( Registry ) are confused, and there is no strict distinction. In fact, there are often multiple warehouses stored on the warehouse registration server, and each warehouse contains multiple mirrors, and each mirror has a different tag. Repositories are divided into two forms: public repositories (Public) and private repositories (Private). The largest public repository is Docker Hub, which houses a huge number of images for users to download. Domestic public repositories include Docker Pool, etc., which can provide mainland users with more stable and fast-reading access. After users create their own image, they can use the push command to upload it to a public or private repository, so that when downloading and using the image on another machine, they only need to pull from the repository.
amount concept.

【Docker technology and its use】Basic Docker Commands

•Docker installation
sudo apt install
•Docker startup and status query
sudo service docker start
sudo service docker status
•Check the version of Docker
sudo docker version
•View local mirror
sudo docker images
•Download image file
sudo docker pull ubuntu
•Run the Ubuntu image
docker run -i -t ubuntu /bin/bash
•delete image file
sudo docker rmi -f hello-world

•View started Docker services (containers)
sudo docker ps –a
•stop docker service
sudo docker stop image-name
•Login to Docker
docker login
•Save the modified Docker container
OPTIONS Description:
-a : the submitted mirror author;
-c : Use the Dockerfile command to create the image;
-m : Description text when submitting;
-p : Pause the container on commit
•Docker can support mounting a directory on a host into an image
docker run -it -v /home/dock/Downloads: /usr/ Downloads ubuntu64 /bin/bash
docker run -it -v /home/dock/Downloads: /usr/ Downloads ubuntu64 /bin/bash
•Docker container deletion
docker rm CONTAINER ID

•Docker image deletion
docker rmi
•Docker container start start/stop/restart
docker start/stop/restart
The docker start command uses the -i option to enable interactive mode
•Query image and container details
docker inspect
docker info
•Connect to a running container
docker attach CONTAINER ID/name
•Exit container without closing
ctrl + d exit to close the container, ctrl + p + q exit the container without closing
•The container installed by Docker's Ubuntu image has no ifconfig command and ping command
apt- get update
apt install net-tools #ifconfig
apt install iputils-ping # ping
•docker Ubuntu install mysql
apt- get update
apt- get install -y mysql-server mysql-client
•Docker container and host file copy
1 ) Copy files from the container to the host
docker cp : /file/ path/within/container /host/path/target
2 ) Copy files from the host to the container
sudo docker cp host_path containerID:container_path
3 ) Problem FATA[ 0000 ] Error : Path not specified
Version 1.6.2 doesn 't allow copying from host to container, you need to upgrade to at least 1.8 for that support
•docker version upgrade

1 ), Docker source installation specified version:
sudo apt- get install apt-transport-https
sudo apt-key adv --keyserver hkp:// --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
sudo bash -c "echo deb https:// get docker main >/etc/apt/sources.list.d/docker.list"
sudo apt - get update --update software sources
sudo apt-cache search docker --find the docker version that needs to be updated
sudo apt - get install lxc-docker-1.9.1
2) Error resolution
After the docker installation is complete, execute sudo service docker start, and an error is displayed: Failed to start docker.service: Unit docker.service is masked.
systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service

•docker container backup
1 ) Generate docker image
docker commit -p 30 b8f18f20b4 container-backup
2 ) We want to upload or backup images in the Docker registry, we just need to run the docker login command to log in to the Docker registry, and then push the required images
( 1 ) docker login
( 2 ) docker tag a25ddfec4d2a arunpyasi/container-backup:test
( 3 ) docker push arunpyasi/container-backup
3 ) If we don't want to backup to docker registry, but want to save this image in local machine for later use, then we can backup it as a tarball. To do that, we need to run the following docker save command.
docker save -o ~ /container-backup.tar container-backup
tar -zcvf ubuntu2-backup.tar.gz container-backup.ta
•docker restore container
1 ) After we have successfully backed up our Docker containers, let's now restore these containers that took a snapshot of the Docker image. If we have pushed these Docker images in the registry, then we just need to drag that Docker image back and run it directly.
docker pull arunpyasi/container-backup:test
2 ) If we back up these Docker images locally as tarball files, then we can load the Docker image as long as we use the docker load command followed by the backup path of the tarball.
tar -zxvf ubuntu2-backup.tar.gz
docker load -i ~ /container- backup.tar
3) Use docker image to view
extc command
Using the attach command often gets stuck, you can use the exec command instead
docker exec -it ubuntu /bin/bash
If you enter with attach above, you will exit the container with exit. You must exit with ctrl PQ to continue running in the background. If you use exec, exit will not really exit the container and continue running in the background. You can use name or id.
•Common commands
docker run --name ubuntu -it ubuntu: 16.04 /bin/bash
docker exec -it 96740370 a5da /bin/bash

Copyright statement: The content of this article is contributed by Alibaba Cloud's real-name registered users. The copyright belongs to the original author. The Alibaba Cloud developer community does not own the copyright and does not assume the corresponding legal responsibility. For specific rules, please refer to the " Alibaba Cloud Developer Community User Service Agreement " and " Alibaba Cloud Developer Community Intellectual Property Protection Guidelines ". If you find any content suspected of plagiarism in this community, fill out the infringement complaint form to report it. Once verified, this community will delete the allegedly infringing content immediately.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us