Table of contents
Manual installation of Docker (CentOS7)
1.1 Uninstall the previous version of Docker
1.2 Install dependent packages
1.3 Update the local mirror source (also called: set the source warehouse)
1.5 Configuring Mirror Acceleration
Other common commands of Docker
Docker settings start automatically at boot
2. View the set startup services
Docker container settings to start automatically
How Docker builds and deploys PHP
How to make a Docker image for CI/CD releases.
Docker and system version
Docker has been divided into CE (Community Edition: Community Edition) and EE (Enterprise Edition: Enterprise Edition) since version 17.03. Compared with the community version, the enterprise version emphasizes security, but needs to be paid for. Here we can use the community version.
Docker supports 64-bit versions of CentOS 7 and CentOS 8 and later, and it requires a Linux kernel version no lower than 3.10.
Check the Linux version of the command Here are two recommended:
lsb_release -a
orcat /etc/redhat-release
.
If the system does not support:lsb_release -a 命令,则使用:cat /etc/redhat-release 即可
Check if the kernel version is not lower than 3.10
There are three ways to check the kernel version:
cat /proc/version
uname -a
uname -r
The content version can be viewed in three forms, such as:
It can be seen that the current Linux kernel version meets the requirements of Docker.
Docker automated installation
Docker official and domestic daocloud both provide one-click installation scripts, making Docker installation more convenient.
The official one-click installation method:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
Domestic daocloud one-key installation command:
curl -sSL https://get.daocloud.io/docker | sh
I have not personally tested the two commands for automated installation. If you are interested, you can test it yourself. I installed Docker manually.
Manual installation of Docker (CentOS7)
- Docker is divided into two major versions, CE and EE. CE stands for Community Edition (free, 7-month support period)
- EE stands for Enterprise Edition, emphasizing security, paid use, and a support cycle of 24 months.
- Docker CE is divided into three update channels: stable test and nightly. There are installation guides in various environments on the official website. Here we mainly introduce the installation of Docker CE on CentOS.
-
1.1 Uninstall the previous version of Docker
This step is optional. If you have installed an old version of Docker before, you can use the following command to uninstall it. If you have not installed Docker, you can skip this step
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 dependent packages
yum-utils provides yum-config-manager, and the device mapper storage driver requires device-mapper-persistent-data and lvm2.
yum install -y yum-utils \device-mapper-persistent-data \lvm2 --skip-broken
-
1.3 Update the local mirror source (also called: set the source warehouse)
Because docker’s default official image source address is foreign, and the speed is very slow, here the data source is set to the image of Alibaba Cloud. Of course, there are other mirror sources in China.
Alibaba Cloud : http : ** // mirrors.aliyun.com/docker-ce/linux/centos/**docker-ce.repo _
Tsinghua University source: https:**// mirrors.tuna.tsinghua.edu.cn / docker-ce / linux / centos /**docker-ce.repo
yum-config-manager \ --add-repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
-
1.4 Docker installation
yum install -y docker-ce
The problem arises, after I execute the yum install -y docker-ce command, I get an error: No package docker-ce available.
Tip: No package docker-ce available. It is because I have not uninstalled the old version of Docker
- 1.4.1 Solution:
Uninstall the old version of docker and its related dependencies
yum remove docker docker-common container-selinux docker-selinux docker-engine
- 1.4.2 Update yum (this process is a little slow)
yum update
- 1.4.3 Install yum-utils, which provides yum-config-manager, which can be used to manage yum sources
yum install -y yum-utils
- 1.4.4 Add yum source, which is equivalent to the command mentioned in [1.3 Update local mirror source]
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- 1.4.5 Update index
centos7的命令:
yum makecache fast
centos8的命令:
yum makecache
- 1.4.6 Execute the install Docker command again
yum install -y docker-ce
-
1.5 Configuring Mirror Acceleration
The network speed of docker's official mirror warehouse is poor, so we need to set up a domestic mirror service:
- 1.5.1 Create a folder (if the folder already exists, you don’t need to create it)
mkdir -p /etc/docker
- 1.5.6 Create a deamon.json file in the folder
#在新建的 daemon.json文件中添加内容
[root@wpl docker]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://akchsmlh.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://akchsmlh.mirror.aliyuncs.com"]
}
#重新加载文件
[root@wpl docker]# sudo systemctl daemon-reload
#重启docker
[root@wpl docker]# sudo systemctl restart docker
#查看docker运行状态
[root@wpl docker]# systemctl status docker
The result of the execution is shown in the figure below
At this point, the Docker installation is basically complete
Docker start
- Command to start Docker:
systemctl start docker
- Verify that Docker Engine-Community is installed correctly by running the hello-world image.
// 拉取镜像
docker pull hello-world
// 执行hello-world
docker run hello-world
- If after execution, the console displays the following information, it means that Docker is successfully installed and started:
- In addition to starting Docker, there are some other startup-related commands:
守护进程重启:
systemctl daemon-reload
重启Docker服务:
systemctl restart docker / service docker restart
关闭Docker服务:
docker service docker stop / docker systemctl stop docker
remove docker
- Remove the installation package:
yum remove docker-ce
- Delete images, containers, configuration files, etc.:
rm -rf /var/lib/docker
Other common commands of Docker
After installing Docker, here is a summary of common Docker operation commands:
Search warehouse images: docker search image name
Pull image: docker pull image name
View running containers: docker ps
View all containers: docker ps -a
Delete container: docker rm container_id
View mirror: docker images
Delete mirror: docker rmi -f mirror name/mirror ID
Load the image: docker load -i image save file location
Start (stopped) container: docker start container ID
Stop the container: docker stop container ID
Restart the container: docker restart container ID
Start the (new) container: docker run -it ubuntu /bin/bash
Into the container:
docker attach 容器ID
ordocker exec -it 容器ID /bin/bash
, the latter is recommended.View docker status: systemctl status docker
Check the docker version: docker -v
View the directory in the container: docker inspect container ID
More commands can
docker help
be viewed through commands.
Docker settings start automatically at boot
-
1. View all started services
systemctl list-units --type=service
-
2. View the set startup services
systemctl list-unit-files | grep enable
Among the services that have been set to start at boot, docker.service cannot be seen.
-
3. Set the boot to start
systemctl enable docker.service
-
4. Turn off the boot
systemctl disable docker.service
After executing the command: systemctl enable docker.service, check again to start the service, and you will see docker.service in the list
Docker container settings to start automatically
- Add --restart=always when starting
For example : start the mysql service and start it together with docker.
docker run -p 3306:3306 --name mysql --restart=always -v /application/mysql/conf:/etc/mysql/conf.d -v /application/mysql/logs:/logs -v /application/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6
- If it has already started, use update to update:
docker update --restart=always 容器id或name
How Docker builds and deploys PHP
The practical operation of this article is to install Docker on Linux. After the installation is completed, it should be applied to the project. How to build and deploy PHP with Docker, please refer to another article I wrote
Docker builds PHP operating environment - Super Le's Blog - CSDN Blog
How to make a Docker image for CI/CD releases.
Making a Docker image, I haven't had time to sort it out, and the follow-up needs to be improved.....