Docker practice (1): install Docker on Ubuntu 16.04

**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

Docker practice (1): install Docker on Ubuntu 16.04
Install docker on Ubuntu
Install Docker on ubuntu18.04
Install Docker on Ubuntu18
Install Docker on Ubuntu 18.04 offline
ubuntu18.04 install docker
docker install ubuntu
Docker ubuntu: install python-PIL-image environment on 14.04
Install Docker on Centos7
install vscode on ubuntu18
Install Redis on Ubuntu
Install R4 on ubuntu20
Install nvtop on Ubuntu 18.04
Install postgresql-10 on Ubuntu 18.04
How to install Docker Compose on Ubuntu 18.04
Install nodejs10 on Ubuntu16
Install mysql on Ubuntu 14.04
Install Django on ubuntu
Install Pytorch+CUDA on Ubuntu 16.04
Install docker on ubuntu and basic usage
Install Python3 on Ubuntu 14.04
Install rJava on Ubuntu18
Install JDK10+ on Ubuntu
Install Python3 on Ubuntu 16.04
Install KDE on Ubuntu16.04.2
install Docker on centos6.5
Install Python3.7 on Ubuntu
Install flashplayer on Ubuntu
How to install Prometheus with Docker on Ubuntu 14.04
How to install and use Docker on Ubuntu 20.04
[Practice] How to install python3.6 on Ubuntu system
How to install and use Docker on Ubuntu 16.04
Install ubuntu on virtual machine
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
Install QQ robot on Ubuntu 16.04
Install Python 3.7 on Ubuntu 18.04 LTS
Install Android Studio on Ubuntu
Install scrapy framework on ubuntu
Install docker transfer on Centos7
Install Mysql offline on Ubuntu
Install Oracle Java8 on Ubuntu
Install docker on Centos system
Install Odoo 11 stack on Ubuntu 16.04
Install Go locale on Ubuntu16
Install common software on Ubuntu 16.04
Install non-portable QQ on ubuntu
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
Install Tenda u12 driver on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
Install and configure MySQL on Ubuntu
Install Chef server workstation on Ubuntu 18.04