1. Initialize the environment
1. Uninstall the old version
First, uninstall any old versions of Docker that may be present. If you are not sure whether you have installed it, you can directly execute the following command:
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2. Update the system
Update system information:
sudo yum update -y
3. Install the dependencies required by Docker
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
2. Set up the Docker image source
To speed up downloading, it is recommended to use a domestic Docker image source.
1. Tencent Cloud Image Source
sudo yum-config-manager \
--add-repo \
https://mirrors.cloud.tencent.com/docker-ce/linux/centos/docker-ce.repo
2. Alibaba Cloud Image Source
sudo yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3. Tsinghua University Mirror Source
sudo yum-config-manager \
--add-repo \
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
4. Official mirror source
Official mirror sources, that is, foreign mirror sources, are slower and may be blocked.
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
3. Install Docker
1. Install the latest version
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
2. Install the specified version
If you need to install a specific version of Docker, you can first query the list of available versions:
yum list docker-ce --showduplicates | sort -r
Based on the query results, select the required version (for example 26.0.0
), and then execute:
sudo yum install -y docker-ce-<VERSION> docker-ce-cli-<VERSION> containerd.io
Replace <VERSION>
with the actual version number.
3. Start and set the system to start automatically
sudo systemctl start docker
sudo systemctl enable docker
4. Verify the installation results
docker info
4. Install Docker Compose
1. Add EPEL repository
sudo yum install -y epel-release
2. Install Docker Compose
sudo yum install -y docker-compose
3. Check the version
docker-compose --version
5. Configure the image accelerator
To increase the speed of pulling images, you can configure an image accelerator.
1. Tencent Cloud Image Accelerator
Editing the Configuration File
sudo vim /etc/docker/daemon.json
Add the following content
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
]
}
2. Alibaba Cloud Image Accelerator
Please refer to Configuring Image Accelerator_Container Registry (ACR) to obtain your dedicated accelerator address.
Add accelerator address
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://<您的阿里云加速器地址>"
]
}
EOF
Replace <您的阿里云加速器地址>
with the actual address.
3. Restart Docker
sudo systemctl daemon-reload
sudo systemctl restart docker
4. Verify the configuration
docker info
In the output, you should see the configured image accelerator.
6. Upload the SpringCloud project to be deployed
Modify the file according to project requirements and deploy the project to the directory under docker-compose.yml
the root directory .docker
7. Initialize the project using Docker Compose
1. Set permissions
sudo chmod -R 777 /docker
2. Enter the project directory
cd /docker
3. Create and run all containers in the background
docker-compose up -d
Wait for the image to be downloaded, built, and the container to be started.
You can view the container status with the following command:
# 查看镜像列表
docker images
# 查看所有容器
docker ps -a
# 查看指定容器的日志
docker logs -f <容器名称>
Visit the project address we deployed.
Deployment Success
4. Renewal container
Rebuild and start the container (when the code is changed)
docker-compose up --force-recreate --build -d <服务名称>
Replace <服务名称>
with docker-compose.yml
the service name defined in .
Restart the container (refresh only)
docker restart <容器名称>