There are several ways to install Docker CE, the following is the easiest method by installing Docker warehouse, other method, see the official documentation .
Setting warehouse
Refresh Package
sudo apt-get update
Install the necessary software packages
sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
Add Docker official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify whether the fingerprint
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
can be verified by 8 after a search of the fingerprint.sudo apt-key fingerprint 0EBFCD88 result: pub rsa4096 2017-02-22 [SCEA] 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid [ unknown] Docker Release (CE deb) <[email protected]> sub rsa4096 2017-02-22 [S]
Use the following command to add stable version warehouse
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
Installation Docker CE
Refresh Package
sudo apt-get update
Install the latest version of the docker ce and containerd
sudo apt-get install docker-ce docker-ce-cli containerd.io
By running
hello-world
a mirror to verify that the installation was successfulsudo docker run hello-world
Docker CE after the installation is complete, will create
docker
a user group, but no user is assigned, so the needsudo
to run Docker command.
other settings
Mirror accelerate domestic container
Use accelerator can improve the speed of image acquisition Docker official, use the following Ali cloud mirror accelerated.
By modifying the daemon configuration file /etc/docker/daemon.json
to use accelerator
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://jjzi6741.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Use non-root user management to run Docker
Reference links
Docker daemons bound Unix socket rather than a TCP port. By default Unix socket attributable to the root
user, other users can only sudo
access the command. So Docker daemon always root
user to run.
If you do not want to run every docker
command in front with sudo
, you can create a docker
user group and the user added. When Docker daemon starts, it will create a Unix socket for docker
user group members to access.
caveat
docker
User group members androot
users have the same privileges, see Docker Daemon Attack Surface to learn more about the impact of system security.
Create a docker
user group and add your user
Creating
docker
user groupssudo groupadd docker
Add your user to
docker
user groupsudo usermod -aG docker $USER
Permission to re-sign in to try to take effect.
Verify that you can not use the
sudo
command to rundocker
docker run hello-world
This command will download and run a test image in the container. After the run is completed, it will display a welcome message and exit.
If you are added to the user
docker
using a user group beforesudo
run-off Docker command, you may encounter the following error message, because~/.docker/
permissions are not caused.WARNING: Error loading config file: /home/user/.docker/config.json - stat /home/user/.docker/config.json: permission denied
To solve this problem, you can delete
~/.docker/
(custom settings will be lost) directory, or use the following command to change permissions.sudo chown "$USER":"$USER" /home/"$USER"/.docker -R sudo chmod g+rwx "$HOME/.docker" -R
Installation Docker Compose
Reference links
In the Linux system, you can Compose repository release page on GitHub to download Docker Compose binaries.
For the
alpine
system, install the following dependencies:py-pip
,python-dev
,libffi-dev
,openssl-dev
,gcc
,libc-dev
make
Run the following command to download the latest stable version Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Download different versions, you can change the version number of the command.
To file with executable permissions
sudo chmod +x /usr/local/bin/docker-compose
Note : If you perform the installation
docker-compose
fails, check thePATH
variables. Also soft link can be established.
such as:
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
(Optional), to
bash
andzsh
mounted Command Completion .Verifying Successful Installation
$ docker-compose --version docker-compose version 1.24.0, build 1110ad01