2019-09-06 08:27:21 +00:00
# # Install Docker CE on Ubuntu
2014-09-11 14:52:28 +00:00
2020-10-26 05:33:37 +00:00
> warning : Don ' t install Docker CE directly using apt without configuring Docker APT source .
2018-03-19 08:04:23 +00:00
2019-09-06 08:27:21 +00:00
# # # Preparation
2016-02-04 06:29:05 +00:00
2019-09-06 08:27:21 +00:00
# # # # System requirements
2016-06-12 10:22:47 +00:00
2020-10-26 05:33:37 +00:00
Docker CE supported [ Ubuntu ] ( https : //www.ubuntu.com/server) versions:
2017-09-04 03:18:14 +00:00
2019-08-31 10:35:14 +00:00
* Disco 19.04
* Cosmic 18.10
2018-07-10 00:07:31 +00:00
* Bionic 18.04 ( LTS )
2017-09-04 15:34:38 +00:00
* Xenial 16.04 ( LTS )
2016-02-04 06:29:05 +00:00
2019-09-06 08:27:21 +00:00
Docker CE can be installed on x86 platform or ARM . In Ubuntu distributions , LTS ( Long - Term - Support ) will get 5 years updating support , distributions like this will be stable . Therefore , LTS version is recommended in production environment .
2016-11-12 17:44:49 +00:00
2019-09-06 08:27:21 +00:00
# # # # Uninstall old version
2016-02-04 06:29:05 +00:00
2019-09-06 08:27:21 +00:00
Old version of Docker is called ` docker ` or ` docker-engine ` . Use the following command to uninstall the old version :
2016-11-12 17:44:49 +00:00
` ` ` bash
2017-10-19 14:41:37 +00:00
$ sudo apt - get remove docker \
docker - engine \
docker . io
2016-11-12 17:44:49 +00:00
` ` `
2019-09-06 08:27:21 +00:00
# # # Use APT to install
2016-11-09 18:32:55 +00:00
2019-09-06 08:27:21 +00:00
Because the ` apt ` source uses HTTPS to ensure that software downloads are not tampered with . Therefore , we need to add software packages and CA certificates that are transmitted using HTTPS first .
2016-11-09 18:32:55 +00:00
2016-11-10 11:48:32 +00:00
` ` ` bash
2017-09-04 03:18:14 +00:00
$ sudo apt - get update
2016-11-08 19:18:30 +00:00
2017-09-04 03:18:14 +00:00
$ sudo apt - get install \
apt - transport - https \
ca - certificates \
curl \
software - properties - common
2016-02-04 06:29:05 +00:00
` ` `
2020-10-26 05:33:37 +00:00
If you are in China , it is strongly recommended to use Chinese sources . The official sources are in the comments .
2016-11-08 19:18:30 +00:00
2019-09-06 08:27:21 +00:00
In order to confirm the validity of the downloaded package , we need to add the ` GPG ` key of the software source .
2016-02-04 06:29:05 +00:00
2016-11-10 11:48:32 +00:00
` ` ` bash
2017-10-19 14:41:37 +00:00
$ curl - fsSL https : //mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
2017-12-08 16:12:02 +00:00
2019-09-06 08:27:21 +00:00
# official
2017-12-08 16:12:02 +00:00
# $ curl - fsSL https : //download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
2016-02-04 06:29:05 +00:00
` ` `
2019-09-06 08:27:21 +00:00
Then , we need to add Docker software source to ` source.list `
2016-11-08 19:18:30 +00:00
2016-11-10 11:48:32 +00:00
` ` ` bash
2017-09-04 03:18:14 +00:00
$ sudo add - apt - repository \
2017-10-19 14:41:37 +00:00
" deb [ arch = amd64 ] https : //mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
2017-09-04 03:18:14 +00:00
$ ( lsb_release - cs ) \
stable "
2016-11-08 19:18:30 +00:00
2019-09-06 08:27:21 +00:00
# official
2017-12-08 16:12:02 +00:00
# $ sudo add - apt - repository \
# " deb [ arch = amd64 ] https : //download.docker.com/linux/ubuntu \
# $ ( lsb_release - cs ) \
2019-02-21 02:53:33 +00:00
# stable "
2016-11-08 19:18:30 +00:00
` ` `
2020-10-26 05:33:37 +00:00
> The above commands will add stable Docker CE APT source . If you need the ` test ` or ` nightly ` version of Docker , you can change ` stable ` to ` test ` or ` nightly ` .
2017-12-08 16:12:02 +00:00
2019-09-06 08:27:21 +00:00
# # # # Install Docker CE
2016-11-08 19:18:30 +00:00
2019-09-06 08:27:21 +00:00
Update apt cache and install ` docker-ce ` :
2016-11-08 19:18:30 +00:00
2016-11-10 11:48:32 +00:00
` ` ` bash
2016-02-04 06:29:05 +00:00
$ sudo apt - get update
2017-09-04 03:18:14 +00:00
$ sudo apt - get install docker - ce
2016-11-08 19:18:30 +00:00
` ` `
2016-04-17 12:10:47 +00:00
2019-09-06 08:27:21 +00:00
# # # Auto install by script
2016-11-08 19:18:30 +00:00
2020-10-26 05:33:37 +00:00
Docker Offical has provided a set of convenient installation scripts which can be installed on Ubuntu for test or dev environments .
2016-11-08 19:18:30 +00:00
2016-11-10 11:48:32 +00:00
` ` ` bash
2017-09-04 03:18:14 +00:00
$ curl - fsSL get . docker . com - o get - docker . sh
$ sudo sh get - docker . sh -- mirror Aliyun
2016-04-17 12:10:47 +00:00
` ` `
2016-11-08 19:18:30 +00:00
2020-10-26 05:33:37 +00:00
The script will have everything prepared and install the stable version of Docker CE for the system after execution .
2016-11-08 19:18:30 +00:00
2019-09-06 08:27:21 +00:00
# # # Launcher Docker CE
2016-11-08 19:18:30 +00:00
2016-11-10 11:48:32 +00:00
` ` ` bash
2017-09-04 03:18:14 +00:00
$ sudo systemctl enable docker
$ sudo systemctl start docker
2016-04-17 12:10:47 +00:00
` ` `
2016-11-08 19:18:30 +00:00
2019-09-06 08:27:21 +00:00
# # # Add docker user group
2016-04-17 12:10:47 +00:00
2020-10-26 05:33:37 +00:00
Command ` docker ` uses [ Unix socket ] ( https : //en.wikipedia.org/wiki/Unix_domain_socket) to communicate with Docker engine default. Only users of `root` and `docker` groups can communicate with Unix socket of Docker engine.`root` user is not directly used on Linux systems in general for security. Therefore, it is better to add users who need to use `docker` to the `docker` user group.
2016-11-08 19:18:30 +00:00
2019-09-06 08:27:21 +00:00
create ` docker ` group :
2016-11-08 19:18:30 +00:00
2016-11-10 11:48:32 +00:00
` ` ` bash
2016-11-08 19:18:30 +00:00
$ sudo groupadd docker
2016-04-17 12:10:47 +00:00
` ` `
2016-11-08 19:18:30 +00:00
2019-09-06 08:27:21 +00:00
add current user to ` docker ` group :
2016-11-08 19:18:30 +00:00
2016-11-10 11:48:32 +00:00
` ` ` bash
2016-11-08 19:18:30 +00:00
$ sudo usermod - aG docker $ USER
2016-04-17 12:10:47 +00:00
` ` `
2019-09-06 08:27:21 +00:00
Exit current terminal and relogin to test .
2017-12-10 05:21:52 +00:00
2019-09-06 08:27:21 +00:00
# # # Test whether Docker is installed correctly
2017-11-24 01:51:06 +00:00
` ` ` bash
$ docker run hello - world
Unable to find image ' hello - world : latest ' locally
latest : Pulling from library / hello - world
2018-10-21 01:51:36 +00:00
d1725b59e92d : Pull complete
Digest : sha256 : 0 add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
2017-11-24 01:51:06 +00:00
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 :
2018-10-21 01:51:36 +00:00
https : //hub.docker.com/
2017-11-24 01:51:06 +00:00
For more examples and ideas , visit :
2018-10-21 01:51:36 +00:00
https : //docs.docker.com/get-started/
2017-11-24 01:51:06 +00:00
` ` `
2020-10-26 05:33:37 +00:00
If it shows above message , it means your installation is successful .
2017-11-24 01:51:06 +00:00
2019-09-06 08:27:21 +00:00
# # # Registry Mirror ( In China )
2017-09-04 03:18:14 +00:00
2019-09-06 08:27:21 +00:00
If you pull docker images very slowly , then you can configurate [ Registry Mirror ] ( mirror . md ) .
2017-09-04 03:18:14 +00:00
2020-10-26 05:33:37 +00:00
# # # References
2016-04-17 13:08:21 +00:00
2019-09-06 08:39:12 +00:00
* [ Offical Docker Docs ] ( https : //docs.docker.com/install/linux/docker-ce/ubuntu/)