Install Docker

Reference: Docker official documentation

Install using the repository

If can go up outside net, recommend this method. For details, see the official documentation link

Install from a package

Note that dependencies are missing. For details, see the official documentation link

Install using the convenience script

For details, see the official documentation link

Install from binaries

You can use this method to access the Intranet only

  1. Download the binary package docker-xx.xx.xx.tgz

Docker official download link Tsinghua University image source download link domestic recommended use this link

  1. Unpack binary
tar -zxvf /path/to/<FILE>.tgz
Copy the code

  1. Copy the decompressed file to the PATH contained in the PATH to use the docker-related commands globally
sudo cp docker/* /usr/bin/
Copy the code
  1. Start the docker daemon
sudo dockerd &
Copy the code
  1. Check whether Docker starts properly
docker --version
Copy the code





Add Docker to Systemd management

  1. Create the docker.service file in /usr/lib/systemd/system/
sudo vim /usr/lib/systemd/system/docker.service
Copy the code
  1. Enter the following
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target  firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local  accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure  StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.targetCopy the code
  1. Setting boot
systemctl enable docker.service
Copy the code
  1. Refresh the configuration
systemctl daemon-reload
Copy the code
  1. Test success
Check the startup status:  systemctl list-unit-files |grep enabled |grep docker systemctl is-enabled docker.service systemctl start docker.service Start systemctl status docker.service Check the status systemctl stop docker.service Stop the systemctl restart docker.service restart ps -ef | grep docker view the docker processCopy the code





3. Docker should replace domestic sources

Change the uSTC and netease image sources and configure DNS

Vim /etc/dock/daemon.json changes to {"registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com" ], "dns": ["223.5.5.5", "223.6.6.6"]} Restart docker systemctl restart dockerCopy the code





4. Use the docker command for non-root users

The permission of non-root users to use docker command prompt is restricted

  1. Create a Docker user group
sudo groupadd docker
Copy the code
  1. Add the current user to the Docker group
sudo gpasswd -a ${USER} docker
Copy the code
  1. Updating group Information
newgrp docker
Copy the code
  1. Restart the docker
sudo systemctl restart docker
Copy the code
  1. Test Execution Result
docker ps
Copy the code





Docker-compose installation

Reference: Docker official documentation

  1. Docker-compose download, if you cannot connect to the Internet, you can download docker-compose, upload it to the server through FTP, and change the file name and storage path
Sudo curl - L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname - s) - $(uname -m)" - o /usr/local/bin/docker-composeCopy the code
  1. Add executable permissions
sudo chmod +x /usr/local/bin/docker-compose
Copy the code
  1. Configure docker-compose globally
Add /usr/local/bin to PATH export PATH=$PATH:/usr/local/bin Create a soft link to the PATH contained in PATH. For example, /usr/bin sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-composeCopy the code

Ps: check the PATH

echo $PAHT
Copy the code

  1. Test docker – compose
docker-compose --version
Copy the code