Centos7 installs Docker&DockerCompose&Docker mirror warehouse

0. Install Docker

Docker is divided into two major versions, CE and EE. CE stands for Community Edition (free of charge, with a support period of 7 months), and EE stands for Enterprise Edition, which emphasizes security and is paid for, with a support period of 24 months. (Just use the free version here)

Docker CE is divided into three update channels stable testand .nightly

There are installation guides in various environments on the official website . Here we mainly introduce the installation of Docker CE on CentOS.

1. Install Docker on CentOS

Docker CE supports the 64-bit version of CentOS 7, and requires a kernel version not lower than 3.10. CentOS 7 meets the minimum kernel requirements, so we install Docker on CentOS 7.

1.1. Uninstall (optional)

If you have installed an old version of Docker before, you can use the following command to uninstall it:

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

1.2. Install docker

First of all, you need to connect the virtual machine to the Internet and install the yum tool (yum-utils)

yum install -y yum-utils \
           device-mapper-persistent-data \
           lvm2 --skip-broken

Then update the local mirror source: (the default foreign source is relatively slow, here is changed to the source of Alibaba Cloud)

# 设置docker镜像源
yum-config-manager \
    --add-repo \
    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

yum makecache fast

Then enter the command:

yum install -y docker-ce

-y means don't ask during the installation process, it's all y

docker-ce is a free version for the community. Wait for a while, docker will be installed successfully.

1.3. Start docker

Docker applications need to use various ports, and modify the firewall settings one by one. It is very troublesome, so it is recommended that you close the firewall directly!

Before starting docker, be sure to close the firewall! !

Before starting docker, be sure to close the firewall! !

Before starting docker, be sure to close the firewall! !

There are too many associated ports, it is more convenient to directly close the firewall when learning

# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld
# 查看防火墙状态
systemctl status firewalld

insert image description here

Start docker by command:

systemctl start docker  # 启动docker服务

systemctl stop docker  # 停止docker服务

systemctl restart docker  # 重启docker服务

Then enter the command to view the docker version:

docker -v

As shown in the picture:

insert image description here

You can also check the docker startup status to verify that docker has started
systemctl status docker
insert image description here

1.4. Configure mirror acceleration

The network speed of docker's official mirror warehouse is poor, so we need to set up a domestic mirror service:

Refer to Alibaba Cloud's mirror acceleration document: https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

Configure Alibaba Cloud’s image acceleration here

insert image description here
Just execute the 4 commands provided by the official document directly

sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://41k3c116.mirror.aliyuncs.com"]
}
EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

After the second command is executed, you can check the file writing status:

cat /etc/docker/daemon.json

insert image description here

2. Install Docker Compose on CentOS7

2.1. Download

Under Linux, you need to download through the command:

# 安装
curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

If the download speed is slow or the download fails, you can use the docker-compose file provided by the pre-class materials:

insert image description here

Uploading to /usr/local/bin/a directory also works.

insert image description here

2.2. Modify file permissions

Modify file permissions:

# 修改权限 (所有用户加上执行权)
chmod +x /usr/local/bin/docker-compose

2.3.Base auto-completion command:

After matching, there will be a code prompt when entering compose

# 补全命令
curl -L https://raw.githubusercontent.com/docker/compose/1.29.1/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose

In fact, it is a file from GitHub: https://raw.githubusercontent.com/docker/compose/1.29.1/contrib/completion/bash/docker-compose
to read the content and write it to the local /etc/bash_completion.d/docker-compose
GitHub. I know that from time to time, the browser Visit that website first, if you can’t visit it, you may have to surf the Internet scientifically

3.Docker mirror warehouse

Building a mirror warehouse can be implemented based on the DockerRegistry officially provided by Docker.
Mirror warehouse: Docker Registry (literally translated into docker registration center, each mirror is an independent microservice, creating a mirror is to register the microservice to the dokcer registration center)

Official website address: https://hub.docker.com/_/registry

3.1. Simplified version of mirror warehouse (not recommended)

Docker's official Docker Registry is a basic version of the Docker image warehouse, which has complete functions of warehouse management, but has no graphical interface.

The construction method is relatively simple, the command is as follows:

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

The command mounts a data volume registry-data to the /var/lib/registry directory in the container, which is the directory where the private mirror library stores data.

Visit http://YourIp:5000/v2/_catalog to view the images contained in the current private image service

3.2. Version with GUI

Developed by an individual, not official.
Use DockerCompose to integrate the official Docker Registry with the UI developed by a third party

Use DockerCompose to deploy DockerRegistry with a graphical interface, the command is as follows:

version: '3.0'
services:
  registry:
    image: registry
    volumes:
      - ./registry-data:/var/lib/registry
  ui:
    image: joxit/docker-registry-ui:static
    ports:
      - 8080:80
    environment:
      - REGISTRY_TITLE=whu私有仓库
      - REGISTRY_URL=http://registry:5000
    depends_on:
      - registry

But the https protocol is not configured, and docker does not trust this service by default.
Do 3.3 first (modify the configuration and restart docker) and then do 3.2

# 新建文件夹
mkdir registry-ui
cd registry-ui
# 创建yml文件
touch docker-compose.yml
# 用本地文件编辑器修改 也就是复制上面内容即可

# 然后在该目录下执行构建命令:下载要花好多时间,耐心等待
docker-compose up -d
# 静待构建完成,最后浏览器访问
http://192.168.141.100:8080/

http://192.168.141.100:8080/
insert image description here

3.3. Configure Docker trust address

Our private server uses the http protocol, which is not trusted by Docker by default, so we need to make a configuration:

# 打开要修改的文件
vi /etc/docker/daemon.json
# 添加内容: 注意ip换成自己的  千万之一上一行加一个,逗号分隔
"insecure-registries":["http://192.168.141.100:8080"]
# 重加载
systemctl daemon-reload
# 重启docker
systemctl restart docker

Guess you like

Origin blog.csdn.net/hza419763578/article/details/131505767