centos docker换源 centos7 docker-ce
Reprint
mob6454cc71b244 2023-07-04 13:14:30
Article tag centos docker source change docker centos linux Docker article classification code life reading number 43
Table of contents
0.Install Docker
1. Install Docker on CentOS
1.1. Uninstall (optional)
1.2.Install docker
1.3.Start docker
1.4. Configure image acceleration
2. Install DockerCompose on CentOS7
2.1.Download
2.2. Modify file permissions
2.3.Base automatically completes commands:
3.Docker image warehouse
3.1. Simplified version of mirror warehouse
3.2. Version with graphical interface
3.3. Configure Docker trust address
0.Install Docker
Docker is divided into two major versions: CE and EE. CE is the community edition (free, support period is 7 months), EE is the enterprise edition, which emphasizes security, is paid for use, and has a support period of 24 months.
Docker CE is divided into three update channels: stable
test
and .nightly
The official website has installation guides for various environments . 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 the kernel version to be no less 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 older version of Docker before, you can uninstall it using the following command:
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, everyone needs to connect the virtual machine to the Internet and install the yum tool.
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2 --skip-broken
Then update the local mirror source:
# 设置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//centos8不适用了
如果报错了,可以使用下面的方式:
yum makecache //centos8适用
//或者下面这个命令也OK
dnf makecache
Then enter the command:
yum install -y docker-ce
- 1.
docker-ce is a community free version. Wait a moment and 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’s very troublesome, so I suggest you turn off the firewall directly!
Before starting docker, be sure to turn off the firewall! !
Before starting docker, be sure to turn off the firewall! !
Before starting docker, be sure to turn off the firewall! !
# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld
Start docker via 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:
1.4. Configure image acceleration
The Internet speed of docker's official image warehouse is poor. We need to set up a domestic image service:
Refer to Alibaba Cloud's image acceleration documentation: Alibaba Cloud Login - Welcome to Alibaba Cloud, a safe and stable cloud computing service platform
2. Install DockerCompose on CentOS7
2.1.Download
Under Linux, you need to download it 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 in the pre-course material:
Uploading to /usr/local/bin/
a directory is also possible.
2.2. Modify file permissions
Modify file permissions:
# 修改权限
chmod +x /usr/local/bin/docker-compose
2.3.Base automatically completes commands:
# 补全命令
curl -L https://raw.githubusercontent.com/docker/compose/1.29.1/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
If an error occurs here, you need to modify your hosts file:
echo "199.232.68.133 raw.githubusercontent.com" >> /etc/hosts
3.Docker image warehouse
Building a mirror warehouse can be achieved based on the DockerRegistry officially provided by Docker.
Official website address: Docker Hub
3.1. Simplified version of mirror warehouse
Docker's official Docker Registry is a basic version of the Docker image warehouse, which has complete functions of warehouse management, but does not have a graphical interface.
The construction method is relatively simple, the commands are 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 image library stores data.
Visit http://YourIp:5000/v2/_catalog to view the images included in the current private image service
3.2. Version with graphical interface
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=传智教育私有仓库
- REGISTRY_URL=http://registry:5000
depends_on:
- registry
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
# 添加内容:
"insecure-registries":["http://192.168.150.101:8080"]
# 重加载
systemctl daemon-reload
# 重启docker
systemctl restart docker