Docker - Install Compose, Mirror Warehouse

Server environment: CentOS7; Installation of Docker (CE)

I. Preparations

1.1 Common Commands

commandexplain
uname -rView the current system kernel version
docker -vView Docker Version
systemctl start dockerStart Docker Service
systemctl stop dockerStop Docker Service
systemctl restart dockerRestart Docker Service
``

1.2 Uninstall Docker (optional)

If you previously installed an older version of Docker, you can uninstall it using the following command:

#Uninstall the Docker command (\: for line break)
yum remove docker \
		docker-client \
		docker-client-latest \
		docker-common \
		docker-latest \
		docker-latest-logrotate \
		docker-logrotate \
		docker-selinux \
		docker-engine-selinux \
		docker-engine \
		docker-ce

2. CentOS7 Installation Docker

2.1 Installation steps

1) First, virtual machine networking is required to install the yum tool:

#yum package updated to the latest
#Install required packages, yum-util provides yum-config-manager functionality, and the other two are devicemapper driven dependent
yum install -y yum-utils device-mapper-persistent-data lvm2 --skip-broken

2) Then update the local mirror source:

Command 1:
#Set yum source (set docker mirror source)
yum-config-manager --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Command 2:
#Set mirror source address
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

Order three:
#Cache package information locally in advance to improve the speed of searching for installed software.
#It is recommended that this command be executed to speed up yum installation
yum makecache fast

3) Install Docker

#Install docker-ce version
yum install -y docker-ce

#Check the docker version to verify that the installation was successful
docker -v

[Tip] The docker-ce is a free version for the community.

2.2 Firewall Settings

_Docker applications require various ports to modify firewall settings one by one. Very troublesome, so I suggest you close the firewall directly during the learning phase! The production environment must not be closed!!
_If you don't close the firewall, you need to open the relevant ports you need!

# Close Firewall Command
systemctl stop firewalld
# Prevent Starting Firewall
systemctl disable firewalld

2.3 Configure Mirror Acceleration

docker's official mirror warehouse has poor network speed, so we need to set up domestic mirror service:

Reference Ali Yun's Mirror Acceleration Document

For Docker client version greater than 1.10. 0 Users
You can modify the daemon configuration file/etc/docker/daemon.json to use the accelerator;

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://bea5ap6l.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

3. CentOS7 Install DockerCompose

3.1 Download DockerCompose

#Download the current stable version of Docker Compose (download its binary package from Github to use)
curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Note: Accessing GitHub's web may cause file download incomplete and damage when downloading files!!!

3.2 Modify file permissions

[root@localhost bin]# pwd
/usr/local/bin
[root@localhost bin]# ll
 Total usage 1536
-rw-r--r--. 1 root root 1570868 11 February 23 19:53 docker-compose

# Add executable permissions to docker compose file
[root@localhost bin]# chmod +x /usr/local/bin/docker-compose

#Check to see if the download was successful (compose version)
[root@localhost bin]# docker-compose -version
docker-compose version 1.29.1, build c34c88b2

3.3 Base AutoCompletion command (optional)

# Automatic Completion Command
curl -L https://raw.githubusercontent.com/docker/compose/1.29.1/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose

If, if, instead of executing the following command, an error occurs here, you need to modify your hosts file:

echo "199.232.68.133 raw.githubusercontent.com" >> /etc/hosts

Restart network card: systemctl restart network

4. Docker mirror warehouse

4.1 Simplified Mirror Warehouse (not recommended)

Docker's official Docker Registry is a base version of the Docker mirror warehouse that provides full warehouse management functionality without a graphical interface.

The construction method is simple and the commands are as follows:

docker run -d \
    --restart=always \
    --name registry \
    -p 5000:5000 \
    -v registry-data:/var/lib/registry \
    registry:2.7.1

The command mounts a data volume registry-data to the / var/lib/registry directory inside the container, which is the directory where the private mirror inventory holds the data.

Access http://server host ip:5000/v2/_catalog can view the images contained in the current private mirroring service;

(Tip) If the following error occurs, modify it step by step:

WARNING: IPv4 forwarding is disabled. Networking will not work.

Step 1: Execute the following command on the host machine

echo "net.ipv4.ip_forward=1" >>/usr/lib/sysctl.d/00-system.conf

Step 2: Restart the network and docker services

systemctl restart network && systemctl restart docker

4.2 with GUI version (recommended)

Deploy DockerRegistry with an image interface using DockerCompose with the following commands:

version: '3.0'
services:
  registry:
    image: registry:2.71 #No tag for the latest image
    volumes:
      - ./registry-data:/var/lib/registry
  ui:
    image: joxit/docker-registry-ui:static
    ports:
      - 8080:80
    environment:
      - REGISTRY_TITLE=slightly drunk CC Private warehouse for
      - REGISTRY_URL=http://registry:5000
    depends_on: #Depends on the registry above
      - registry

4.3 Configure Docker Trust Address

Our private service uses the http protocol and is not trusted by Docker by default, so we need to configure it:

# Open the file you want to modify
vi /etc/docker/daemon.json
# Add: (Fill in the ip of your virtual machine with the port exposed above)
"insecure-registries":["http://192.168.238.66:8080"]
# Reload
systemctl daemon-reload
# Restart docker
systemctl restart docker

Keywords: Linux Operation & Maintenance Docker IDE

Added by mortal991 on Tue, 21 Dec 2021 01:49:15 +0200