**Foreword: **
Docker is divided into an open source and free CE (Community Edition) version and a paid EE (Enterprise Edition) version. This article installs the community version, which is also an ideal choice for developers and small teams.
**Version requirements: **
Cosmic 18.10
Bionic 18.04(LTS)
Xenial 16.04(LTS)
Docker CE supports the above version of Ubuntu 64-bit system, the operating system version of this article is: 16.04.5 LTS (Xenial Xerus)
root@ubuntu1604:~# more /etc/os-release
NAME="Ubuntu"
VERSION="16.04.5 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.5 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
**For ubuntu installation details, please refer to **: [Ubuntu16.04.5 installs all records in lvm mode] (https://blog.51cto.com/3241766/2323927)
The operating system has been configured with Aliyuan and allows root to log in directly.
1. Installation
1. Uninstall the old docker version
root@ubuntu1604:~# root@ubuntu1604:~# apt-get remove docker docker-engine docker.io containerd runc
If the old version of docker has not been installed before, this step can be ignored.
2. Update software list
root@ubuntu1604:~# apt-get update
3. Allow apt command to use HTTPS to access Docker repository
root@ubuntu1604:~# apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
4. Add Docker official GPG key
root@ubuntu1604:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verification key
root@ubuntu1604:~# apt-key fingerprint 0EBFCD88
8 digits after the search can display the completion key
5. Set the repository version to stable and update the software list
root@ubuntu1604:~# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
root@ubuntu1604:~# apt-get update
There are three update methods for Docker CE: stable, test and nightly. For details, see: https://docs.docker.com/install/
6. Install Docker CE and containerd
root@ubuntu1604:~# apt-get install docker-ce docker-ce-cli containerd.io
View docker version
root@ubuntu1604:~# docker --version
Docker version 18.09.2, build 6247962
Due to network reasons, the installation process may fail, just re-execute the installation command. Installed in this way is the latest version of Docker CE and containerd, the version is 18.09.2.
If you need to install a specific version, you can do the following:
Available version query
root@ubuntu1604:~# apt-cache madison docker-ce
The second column is the version list
The installation command for the specified version
apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
For example, install version 18.09.0
root@ubuntu1604:~# apt-get install docker-ce=18.06.2~ce~3-0~ubuntu docker-ce-cli=18.06.2~ce~3-0~ubuntu containerd.io
7. Run the container
Run apache
root@ubuntu1604:~# docker run -d -p 80:80 httpd
Visit apache
The container is running normally
2. Mirror Accelerator
Since the Docker Hub server is located abroad, it will be slower to download the image, you can configure the image accelerator. The main accelerators are: China registry mirror, Alibaba Cloud accelerator, and DaoCloud accelerator officially provided by Docker. This article takes the configuration of Alibaba accelerator as an example.
1. Log in to Alibaba Cloud Container Module
The login address is: https://cr.console.aliyun.com, if you have not registered, you can register an Alibaba Cloud account first
Choose mirror accelerator, choose ubuntu for operating system
2. Configure Mirror Accelerator
Configure the daemon.json file
root@ubuntu1604:~# mkdir -p /etc/docker
root@ubuntu1604:~#tee /etc/docker/daemon.json <<-'EOF'{"registry-mirrors":["https://v16stybc.mirror.aliyuncs.com"]}
EOF
Restart service
root@ubuntu1604:~# systemctl daemon-reload
root@ubuntu1604:~# systemctl restart docker
The accelerator configuration is complete
Three, command completion
Through the bash_complete script, docker provides an automatic completion function. When the command is executed, the parameters can be automatically completed by typing tab, which greatly improves the efficiency of command input.
1. Install bash-completion
root@ubuntu1604:~# apt install bash-completion
2. Load bash-completion
root@ubuntu1604:~# source /etc/bash_completion
Now you can use tab to complete the command:
**Four, uninstall **
1. Uninstall Docker CE installation package
root@ubuntu1604:~# apt-get purge docker-ce
2. Delete related directories and configuration files
root@ubuntu1604:~# rm -rf /var/lib/docker
root@ubuntu1604:~# rm -rf /etc/docker
If there are docker-related configuration files or directories in other paths, delete them as well.
This article references:
https://docs.docker.com/install/linux/docker-ce/ubuntu/
Recommended Posts