Centos Stream 9 configures yum Tsinghua source, refer to my article, click to jump
Uninstall the old version related commands:
yum remove docker \ docker-client\ docker-client-latest\ docker-common\ docker-latest\ docker-latest-logrotate\ docker-logrotate\ docker-engine
1. Update existing yum
yum update
2. Install using repository
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
delete cache package
yum clean packages
3. Install docker engine
When the selection appears, press y
yum install docker-ce docker-ce-cli containerd.io
4. Configure Docker image accelerator:
Log in to Alibaba Cloud – search for Mirror Accelerator and get the address (this is mine, it should be different for everyone): https://yqihq9sh.mirror.aliyuncs.com
create:
sudo mkdir -p /etc/docker
Add to:
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://yqihq9sh.mirror.aliyuncs.com"] } EOF
Service overload:
sudo systemctl daemon-reload
Restart docker:
sudo systemctl restart docker
View configuration:
cat /etc/docker/daemon.json
5. Related commands
View version docker --version
Start systemctl start docker
View status systemctl status docker
Self-start systemctl enable docker
Restart systemctl restart docker
stop systemctl stop docker
6. Pull image
Take fastdfs as an example to pull the image
If the download speed is slow, download from https://hub.docker.com/, upload the image package to the Linux server, and load the image throughdocker load -i fdfs.tar
.
Usedocker images
to see if it is successful
6.1 Pull mirror
The latest is pulled by default, add :1 to specify the version as 1
docker pull morunchang/fastdfs
6.2 Running tracker
docker run -d --name tracker --net=host morunchang/fastdfs sh tracker.sh
6.3 Running storage
docker run -d --name storage --net=host -e TRACKER_IP=machine IP:22122 -e GROUP_NAME=custom group name morunchang/fastdfs sh storage.sh
For example:
docker run -d --name storage --net=host -e TRACKER_IP=192.168.20.221
:22122 -e GROUP_NAME=group1
morunchang/fastdfs sh storage.sh
- The network mode used is –net=host, and the machine IP is replaced with the server IP
- Customize the group name, that is, the storage group
- If you want to add a new storage server, run this command again, pay attention to replace the new group name
6.4 Modify nginx configuration
Enter the storage container and modify nginx.conf
docker exec -it storage /bin/bash
After entering the container
6.4.1 Query Nginx installation location
where is nginx
6.4.2 Check the current Nginx process
ps aux | grep nginx
6.4.3 Modify Nginx configuration file
vi /etc/nginx/conf/nginx.conf
6.4.4 Modify Nginx configuration content (modify the port to 80)
server {<!-- --> listen 80; server_name localhost; location ~ /M00 {<!-- --> # storage The location where the image is actually stored root /data/fast_data/data; ngx_fastdfs_module; } }
storage storage location /data/fast_data/data
6.4.5 Enter the Nginx sbin directory and reload the Nginx configuration file
cd /etc/nginx/sbin
6.4.6 Reload configuration file
./nginx -s reload
If the error (2: No such file or directory) is reported, first specify the configuration file to start
/etc/nginx/sbin/nginx -c /etc/nginx/conf/nginx.conf
6.4.7 Exit container
exit
7. Set up a bootable container
docker update --restart=always tracker
docker update --restart=always storage
Common commands:
View local mirror docker images
Search mirror docker search redis:[version number]
Pull image (no version number is required, the latest one is pulled by default) docker pull redis:[version number]
View all images ID: docker images -q
Delete image docker rmi image ID
Delete image docker rmi image name: version
Delete all images (use with caution): docker rmi docker images -q
View the list of running containers docker ps
View the list of historical running containers docker ps -a
Create a container docker run -it --name= a container name image name /bin/bash
- -i: always run
- -t: Assign terminal to receive commands
- -name= (or space) container name
- -d to run the container in the background,
- Do not enter the container without adding /bin/bash
Enter container: docker exec -it container name /bin/bash
Stop the container: docker stop container name
Start container: docker start container name
Delete container docker rm container name (ID)
View container information: docker inspect container name
Container logs docker logs container ID
Exit container docker restart container ID
View all container IDs: docker ps -aq
Delete all containers (use with caution): docker rm docker ps -aq
Container starts automatically at boot docker update --restart=always container ID
8. About uninstalling docker
systemctl stop docker
yum remove docker-ce docker-ce-cli http://containerd.io
rm -rf /var/lib/docker
rm -rf /var/lib/containerd