002.Docker installation and deployment

Keywords: Linux Docker yum sudo

One docker installation CentOS system

1.1 docker automatic installation script

  1 root@docker:~# wget -qO- https://get.docker.com/ | sh
  2 Or -
  3 root@docker:~# curl -sSL https://get.docker.com/ | sh
 
Note: if the following error occurs, you can use yum to resolve the dependency——
Delta RPMs disabled because /usr/bin/yum provides applydeltarpmnot installed.
  1 yum provides applydeltarpm			#Query the package of the missing applydeltarpm
  2 yum install libdevmapper* -y
  3 yum -y install deltarpm			#Install this package
  4 yum install -y epel-release			#The error may still be prompted. Install this package
  5 root@docker:~# docker version		#Query docker version
 

1.2 docker yum installation

  1 root@docker:~# yum -y remove docker \
  2                   docker-client \
  3                   docker-client-latest \
  4                   docker-common \
  5                   docker-latest \
  6                   docker-latest-logrotate \
  7                   docker-logrotate \
  8                   docker-selinux \
  9                   docker-engine-selinux \
 10                   docker-engine			               #If there is an old version that requires a new installation, uninstall the old version
 11 root@docker:~# yum -y update
 12 root@docker:~# yum install -y yum-utils \
 13 device-mapper-persistent-data \
 14 lvm2
 15 root@docker:~# yum-config-manager \
 16 --add-repo \
 17 https://download.docker.com/linux/centos/docker-ce.repo ා configure the docker source
 
Tip: you can also use domestic alicloud——
  1 root@docker:~# yum-config-manager \
  2 --add-repo \
  3 http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4 root@docker:~# yum-config-manager --enable docker-ce-edge	        #Kai Qi Kai
  5 root@docker:~# yum-config-manager --enable docker-ce-test	        #Kai Qi Kai
  6 root@docker:~# yum -y install docker-ce				#Install docker
  7 root@docker:~# yum -y install docker-registry			#Install docker warehouse
  8 root@docker:~# systemctl start docker.service
  9 root@docker:~# systemctl enable docker.service		        #Set to startup
 
 

2. docker installation - Ubuntu system

2.1 update source database

  1 root@docker:~# apt-get remove docker docker-engine docker.io	#Uninstall old version
  2 root@docker:~# sudo apt-get update
 

2.2 install software package

  1 root@docker:~# sudo apt-get -y install \
  2 apt-transport-https \
  3 ca-certificates \
  4 curl \
  5 software-properties-common			#Install the package to allow apt to use the repository over HTTPS
 

2.3 add the official GPG key of Docker

  1 root@docker:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Note: Alibaba cloud GPG can also be added:
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

2.4 verify secret key fingerprint

  1 root@docker:~# sudo apt-key fingerprint 0EBFCD88

2.5 configure the warehouse and update the source here

  1 root@docker:~# sudo add-apt-repository \
  2 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  3 $(lsb_release -cs) \
  4 stable"
  5 root@docker:~# sudo apt-get update
 
Note: it is recommended to configure Alibaba warehouse in China. The command is as follows:
  1 root@docker:~# sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  2 root@docker:~# sudo apt-get update
 

2.6 installing docker ce

  1 root@docker:~# sudo apt-get -y install docker-ce

2.7 test and view version

  1 root@docker:~# sudo docker run hello-world
  2 root@docker:~# sudo docker version
 
Note: if there is an old version, you can uninstall the old version by executing the following command——
apt-get remove docker docker-engine docker-common container-selinux docker-selinux

III. docker related optimization

3.1 configure docker accelerator

  1 root@docker:~# mkdir -p /etc/docker
  2 root@docker:~# vim /etc/docker/daemon.json
  3 {
  4    "registry-mirrors": ["https://dbzucv6w.mirror.aliyuncs.com"]
  5 }
  6 root@docker:~# cat /etc/docker/daemon.json
  7 {
  8   "registry-mirrors": ["https://dbzucv6w.mirror.aliyuncs.com"]
  9 }
 10 root@docker:~# systemctl daemon-reload
 11 root@docker:~# systemctl restart docker
 12 root@docker:~# sudo systemctl enable docker
 
Tip: docker uses https://hub.docker.com/ to build an image sharing ecosystem. Because it is slow to pull sources from abroad, it is recommended to configure domestic Alibaba accelerator.

3.2 change the docker image path

  1 root@docker:~# vi /usr/lib/systemd/system/docker.service
  2 ExecStart=/usr/bin/dockerd-current --graph=/data/docker		#Just append new path
  3 root@docker:~# systemctl daemon-reload
  4 root@docker:~# systemctl restart docker
Reference resources: https://docs.docker.com/install/

Posted by spstieng on Sat, 07 Dec 2019 22:30:31 -0800