2020-10-26 13:54:27 +08:00
# # Install Docker CE on Debian
> WARNING : DO NOT install Docker with apt directly without configuring apt source .
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
# # # Prerequisites
2018-03-19 16:04:23 +08:00
2020-10-26 13:54:27 +08:00
# # # # OS Requirement
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
Docker CE supports the following [ Debian ] ( https : //www.debian.org/intro/about) versions.
2017-09-04 11:18:25 +08:00
2018-11-02 08:01:29 +08:00
* Buster 10
2017-09-04 23:34:38 +08:00
* Stretch 9
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
# # # # Uninstall the Old Versions
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
The old versions of Docker are called ` docker ` or ` docker-engine ` , you can have them uninstalled with the following command :
2017-09-04 11:18:25 +08:00
` ` ` bash
2017-10-19 22:41:37 +08:00
$ sudo apt - get remove docker \
docker - engine \
docker . io
2017-09-04 11:18:25 +08:00
` ` `
2020-10-26 13:54:27 +08:00
# # # Install with apt
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
Since the apt source uses HTTPS to make sure that the software is not modified maliciously during download , we have to add the apt source via HTTPS as well as the CA certificate .
2017-09-04 11:18:25 +08:00
` ` ` bash
$ sudo apt - get update
$ sudo apt - get install \
apt - transport - https \
ca - certificates \
curl \
gnupg2 \
lsb - release \
software - properties - common
` ` `
2020-10-26 13:54:27 +08:00
Due to the network issues in China mainland , it is highly recommended for Chinese users to use Chinese sources . Please refer to the official sources in the comments ( they are replaced by a Chinese source ) .
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
To verify the validity of the package downloaded , we have to add the GPG key for the package source .
2017-09-04 11:18:25 +08:00
` ` ` bash
2017-10-19 22:41:37 +08:00
$ curl - fsSL https : //mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -
2017-12-09 00:12:02 +08:00
2020-10-26 13:54:27 +08:00
# Official source
2017-12-09 00:12:02 +08:00
# $ curl - fsSL https : //download.docker.com/linux/debian/gpg | sudo apt-key add -
2017-09-04 11:18:25 +08:00
` ` `
2020-10-26 13:54:27 +08:00
After that , we need to add the Docker CE source to ` source.list ` :
2017-09-04 11:18:25 +08:00
` ` ` bash
$ sudo add - apt - repository \
2018-03-19 16:04:23 +08:00
" deb [ arch = amd64 ] https : //mirrors.ustc.edu.cn/docker-ce/linux/debian \
2017-09-04 11:18:25 +08:00
$ ( lsb_release - cs ) \
stable "
2020-10-26 13:54:27 +08:00
# Official source
2017-12-09 00:12:02 +08:00
# $ sudo add - apt - repository \
# " deb [ arch = amd64 ] https : //download.docker.com/linux/debian \
# $ ( lsb_release - cs ) \
2019-02-21 10:53:33 +08:00
# stable "
2017-09-04 11:18:25 +08:00
` ` `
2020-10-26 13:54:27 +08:00
> The above commands will add the APT source for the stable version of Docker CE . If you need the ` test ` or ` nightly ` source , please replace with them to meet your own needs .
2017-12-09 00:12:02 +08:00
2020-10-26 13:54:27 +08:00
# # # # Install Docker CE
2017-09-04 11:18:25 +08:00
2020-10-26 15:03:45 +08:00
Update apt cache and install ` docker-ce ` .
2017-09-04 11:18:25 +08:00
` ` ` bash
$ sudo apt - get update
$ sudo apt - get install docker - ce
` ` `
2020-10-26 13:54:27 +08:00
# # # Install with Automatic Scripts
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
To simplify the installation process during test or development , Docker official provides a convenient installation script , you can install docker on Debian with the following script :
2017-09-04 11:18:25 +08:00
` ` ` bash
$ curl - fsSL get . docker . com - o get - docker . sh
$ sudo sh get - docker . sh -- mirror Aliyun
` ` `
2020-10-26 14:08:12 +08:00
After execution , the script will have everything prepared , and have installed the stable version on your OS .
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
# # # Start Docker CE
2017-09-04 11:18:25 +08:00
` ` ` bash
$ sudo systemctl enable docker
$ sudo systemctl start docker
` ` `
2017-10-19 22:41:37 +08:00
2020-10-26 13:54:27 +08:00
# # # Add Docker Usergroups
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
Command ` docker ` uses [ Unix socket ] ( https : //en.wikipedia.org/wiki/Unix_domain_socket) to communicate with Docker engine by default. Only users of `root` and `docker` groups can communicate with Unix socket of the 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.
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
create ` docker ` group :
2017-09-04 11:18:25 +08:00
` ` ` bash
$ sudo groupadd docker
` ` `
2020-10-26 13:54:27 +08:00
add current user to ` docker ` group :
2017-09-04 11:18:25 +08:00
` ` ` bash
$ sudo usermod - aG docker $ USER
` ` `
2020-10-26 13:54:27 +08:00
Exit current terminal and relogin to test .
2017-12-10 13:21:52 +08:00
2020-10-26 14:08:12 +08:00
# # # Verify the Installation
2017-11-24 09:51:06 +08:00
` ` ` bash
$ docker run hello - world
Unable to find image ' hello - world : latest ' locally
latest : Pulling from library / hello - world
2018-10-21 09:51:36 +08:00
d1725b59e92d : Pull complete
Digest : sha256 : 0 add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
2017-11-24 09:51:06 +08: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 09:51:36 +08:00
https : //hub.docker.com/
2017-11-24 09:51:06 +08:00
For more examples and ideas , visit :
2018-10-21 09:51:36 +08:00
https : //docs.docker.com/get-started/
2017-11-24 09:51:06 +08:00
` ` `
2020-10-26 14:08:12 +08:00
If it shows the above message , it means your installation is successful .
2017-11-24 09:51:06 +08:00
2020-10-26 13:54:27 +08:00
# # # Registry Mirror ( In China )
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
If you pull docker images very slowly , then you can configure [ Registry Mirror ] ( mirror . md ) .
2017-09-04 11:18:25 +08:00
2020-10-26 13:54:27 +08:00
# # # References
2017-09-04 11:18:25 +08:00
2020-10-26 14:08:12 +08:00
* [ Docker Official Installation Documents for Debian ] ( https : //docs.docker.com/install/linux/docker-ce/debian/)