1. Install the latest version of Docker
The default version of centos7 is 1.13. To install a new version, uninstall the older version first
1.1 Delete an earlier Version
-
Tell the docker service systemctl to stop the docker
-
View the current version of the RPM – qa | grep docker
-
Uninstalling software Packages
yum erase docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine \ docker-ce Copy the code
-
Deleting Related Configurations
find /etc/systemd -name '*docker*' -exec rm -f {} \; find /etc/systemd -name '*docker*' -exec rm -f {} \; find /lib/systemd -name '*docker*' -exec rm -f {} \; rm -rf /var/lib/docker Delete the existing image and container, not necessary rm -rf /var/run/docker Copy the code
1.2 Installing the latest version
-
Upgrading the System Package
yum update
-
Software Package Installation
yum install -y yum-utils device-mapper-persistent-data lvm2
-
Add yum source
yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo Copy the code
-
View installable versions
yum list docker-ce --showduplicates | sort -r
-
Install the latest version
yum install docker-ce -y
-
Start and enable autoboot
systemctl start docker systemctl enable docker Copy the code
-
View the Docker version
docker version
2. Solve the problem that the Internet cannot access the Docker port after it is mapped to the host in Linux
Conf or vi /usr/lib/sysctl.d/00-system.conf add the following code: Net.ipv4. ip_forward=1 Restart the network service systemctl restart network and check whether the IP address is changed successfully If net.ipv4.ip_forward = 1 is displayed, the system succeedsCopy the code
3. Docker starts automatically after startup
sudo systemctl enable docker
sudo systemctl start docker
Copy the code
4. Docker views logs
docker logs -f -t --since="2017-05-31"--tail=10 edu_web_1 docker logs [OPTIONS] CONTAINER OPTIONS: --details Displays more information-fSince string Outputs the start date of the log, i.e., only outputs logs after the specified date. --tail string Displays the last number of lines of the log. The default is all (-tail=10: views the last 10 lines of the log.)Copy the code
5. Clean up the docker disk space and migrate the /var/lib/docker directory
-
View disk usage
du -hs /var/lib/docker/
-
Migrate the /var/lib/docker-/ directory
-
Stop the Docker service
systemctl stop docker
-
To create a new docker directory, run df -h to find a large disk. /home/ docker-lib /lib /home/ docker-lib /lib /home
mkdir -p /home/docker/lib
-
Migrate files under /var/lib/docker directory to /home/docker-lib
rsync -avz /var/lib/docker /home/docker/lib/
-
Configure the/etc/systemd/system/docker. Service. D/devicemapper. Conf. Check whether devicemapper.conf exists. If it does not exist, create one
mkdir -p /etc/systemd/system/docker.service.d/ vi /etc/systemd/system/docker.service.d/devicemapper.conf Copy the code
-
/home/docker/lib/docker/devicemapper.conf/devicemapper.conf/devicemapper.conf
[Service] ExecStart= ExecStart=/usr/bin/dockerd --graph=/home/docker/lib/docker Copy the code
-
Reload the Docker
systemctl daemon-reload systemctl restart docker Copy the code
-
To make sure everything goes well, run the docker info command to check the root directory of the Docker. It will be changed to /home/dock/lib/docker
. Docker Root Dir: /home/docker/lib/docker Debug Mode (client):false Debug Mode (server): false Registry: https://index.docker.io/v1/ Copy the code
-
After successful startup, confirm that the previous image is still there: Docker Images
-
Delete the files in the /var/lib/docker-/ directory
-
6. Docker limits the container log size
-
Create /etc/docker-daemon. json if it already exists, do not create it
-
Add the log-opts parameter
"log-driver":"json-file"."log-opts": {"max-size" :"50m"."max-file":"1"} Copy the code
-
Load the configuration file and restart
systemctl daemon-reload systemctl restart docker Copy the code