Docker online and offline deployment

1. Docker is deployed online

1. Check whether the system configuration supports Docker

uname -r
#CentOS > 3.10
Copy the code

2. Update the yum version, check the required dependencies, and set the yum source

yum update
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Copy the code

3. Install the specified version of Docker

yum list docker-ce --showduplicates | sort -r
yum install docker-ce-xx.xx.x.ce
systemctl start docker
systemctl enable docker
docker version
Copy the code

4. Install the docker – compose

Curl - https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname - s) - $L (uname -m) - o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-composeCopy the code

2. Deploy the Docker offline

1. Download Docker and Docker-compose

#docker
https://download.docker.com/linux/static/stable/x86_64/
https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
#docker-compose
https://github.com/docker/compose/releases
https://github.com/docker/compose/releases/download/1.29.1/docker-compose-Linux-x86_64
Copy the code

2. Install

#docker
tar -zxvf docker-xx.xx.x-ce.tgz
cp xxx /usr/bin/
cd /etc/systemd/system/
touch docker.service
vim docker.sevive
--------------------------------
[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 --selinux-enabled=false --insecure-registry=####YOURserviceIP
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.target
 ------------------------------------------
 chmod 777 /etc/systemd/system/docker.service
 systemctl daemon-reload
 systemctl start docker
 systemctl enable docker.service
 systemctl status docker
 
#docker-compose
cd  /usr/local/bin
mv  docker-compose-Linux-x86_64  docker-compose
chmod +x docker-compose
docker-compose --version
Copy the code

3. Docker configures the repository source

1. Configure the domestic mirror source

vi /etc/docker/daemon.json
--------------------------
{"registry-mirrors": ["http://hub-mirror.c.163.com"]}
--------------------------
service docker restart
Copy the code

2. Build a local warehouse

#Use the command to create the warehouse dockR
docker run -d -p 8081:8080 atcol/docker-registry-ui
##8081: Specifies the port.
#Host host IP + port:
##https://github.com/atcol/docker-registry-ui
Copy the code

Docker basic instructions

1. Run docker related

#Get the image from the Docker repository
docker pull {tag}
#Start the container with an imageDocker run-itd --name {container name} {IDor image name} /bin/bash/#View the running container
docker ps
#Into the containerDocker exec it {container name or container ID} /bin/bash/#Start the stopped containerDocker start {container ID}#Stop the containerDocker stop {container ID}Copy the code

2. Make the Docker image

  • **REPOSITORY: ** represents the REPOSITORY source of the image
  • **TAG: ** image TAG
  • **IMAGE ID: **IMAGE ID
  • **CREATED: ** Image creation time
  • **SIZE: ** Mirror SIZE
#Export the container as an image tar packageDocker export {container ID} > {tar package name}.tar#Import the container tar package as an imageThe cat {tar package name}. Tar | docker import - {repository} : {TAG}#Remove the containerDocker rm -f {container ID}Copy the code

3. Other docker commands

# 
docker load < {}.tar
#

Copy the code