Docker Tutorial
Docker Installation
How to use Docker
Docker Instance
Docker Container Lifecycle Command
Docker Container Operation Command
Docker Container rootfs Command
Docker Mirror Repository Command
Docker Local Image Management Command
Docker info|version Command
Docker Engine-Community supports the following Ubuntu versions:
Docker Engine - Community supports armhf, arm64, s390x (IBM Z), and ppc64le (IBM Power) architectures on x86_64 (or amd64).
The installation command is as follows:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
Older versions of Docker were called docker, docker.io or docker-engine. If installed, uninstall them:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
Currently called the Docker Engine-Community package docker-ce.
To install Docker Engine-Community, two methods are described below.
Before installing Docker Engine-Community for the first time on a new host, you need to set up the Docker repository. After that, you can install and update Docker from the repository.
Update the apt package index.
$ sudo apt-get update
Install apt dependencies for fetching repositories over HTTPS:
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
Add Docker's official GPG key: 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88. Verify that you now have the key with the fingerprint by searching for the last 8 characters of the fingerprint.
$ sudo apt-key fingerprint 0EBFCD88 pub rsa4096 2017-02-22 [SCEA] 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid [ unknown] Docker Release (CE deb) <docker@docker.com> sub rsa4096 2017-02-22 [S]
Update the apt package index.
$ sudo apt-get update
Install the latest versions of Docker Engine-Community and containerd, or go to the next step to install a specific version:
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Install a specific version using a version string, such as 5:18.09.1~3-0~ubuntu-xenial.
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
To test whether Docker is successfully installed, enter the following command and print the following information to indicate that the installation is successful:
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
Docker provides convenience scripts at get.docker.com and test.docker.com that will quickly install edge and test versions of Docker Engine-Community. The source code for the script is in the docker-install repository. Using these scripts in a production environment is not recommended and you should understand the potential risks before using them:
The script needs to be run as root or with sudo privileges. Therefore, scripts should be carefully checked and audited before running them.
These scripts attempt to detect the Linux distribution and version and configure the package management system for you. Also, the script does not allow you to customize any installation parameters. This can lead to unsupported configurations from a Docker perspective or from your own organization's guidelines and standards.
These scripts will install all dependencies and recommendations of the package manager without confirmation. This may install a large number of packages, depending on the current configuration of the host.
The script does not provide an option to specify which version of Docker to install, instead it installs the latest version published in the edge channel.
Do not use convenience scripts if Docker is already installed on the host using another mechanism.
This example uses the script at get.docker.com to install the latest version of Docker Engine-Community on Linux. To install the latest test version, use test.docker.com instead. In each command below, replace each occurrence of get with test.
$ curl -fsSL https://get.docker.com -o get-docker.sh $ sudo sh get-docker.sh
If you want to use Docker as a non-root user, you should consider adding the user to the docker group using something like:
$ sudo usermod -aG docker your-user
Remove the installation package:
sudo apt-get purge docker-ce
Delete images, containers, configuration files, etc.:
sudo rm -rf /var/lib/docker
Install Docker on Ubuntu 16.04
1. Select a domestic cloud service provider, here Alibaba Cloud is selected as an example
curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh -
2. Install the required packages
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
3. Add the package using HTTPS and the CA certificate
sudo apt-get update sudo apt-get install apt-transport-https ca-certificates
4. Add GPG key
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
5. Add software source
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
6. Update the package cache after adding successfully
sudo apt-get update
7. Install docker
sudo apt-get install docker-engine
8. Start docker
sudo systemctl enable docker sudo systemctl start docker
Install Docker-ce on Ubuntu 18.04
1. Replace the domestic software source, recommend the source of the University of Science and Technology of China, and the stability is fast (optional)
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list sudo apt update
2. Install the required packages
sudo apt install apt-transport-https ca-certificates software-properties-common curl
3. Add the GPG key and add the Docker-ce software source, here is the Docker-ce source of the University of Science and Technology of China as an example
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \ $(lsb_release -cs) stable"
4. Update the package cache after adding successfully
sudo apt update
5. Install Docker-ce
sudo apt install docker-ce
6. Set up self-start and start Docker-ce (after the installation is successful, it is set and started by default, which can be ignored)
sudo systemctl enable docker sudo systemctl start docker
7. Test Run
sudo docker run hello-world
8. Add the current user to the docker user group, you can run docker without sudo (optional)
sudo groupadd docker sudo usermod -aG docker $USER
9. Test adding user groups (optional)
docker run hello-world
I installed it on Tencent Cloud for a long time without success. It is an Ubuntu environment. Finally, I tried one myself.
1. Installation
# apt-get install -y docker.io
start up
# service docker start
Check
# docker -v Docker version 18.09.5, build e8ff056
Check and fix
# apt update
install patch
# apt-get update
2. Mirror
Check out the local mirror:
docker images
# docker images REPOSITORY TAG IMAGE ID CREATED SIZE
Search mirrors:
docker search...
# docker search tomcat NAME DESCRIPTION STARS OFFICIAL AUTOMATED tomcat Apache Tomcat is an open source implementati… 2403 [OK] tomee Apache TomEE is an all-Apache Java EE certif… 66 [OK] dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base… 53 [OK] bitnami/tomcat Bitnami Tomcat Docker Image 28 [OK] ...omit
Pull the image:
docker pull...
# docker pull tomcat Using default tag: latest latest: Pulling from library/tomcat ...omitting the code Digest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe Status: Downloaded newer image for hello-world:latest
Delete mirror:
docker rmi...
# docker rmi hello-world Untagged: hello-world:latest Untagged: hello-world@sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe Deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e Deleted: sha256:af0b15c8625bb1938f1d7b17081031f649fd14e6b233688eea3c5483994a66a3