Docker update

Posted by elentz on Tue, 21 Apr 2020 11:06:05 +0200

Docker update

Original version 1.10

Updated version 19.03.1

To update Docker version:

  • Note whether the system supports the new version of the storage driver.

    The default storage driver for version 19.03.01 is overlay2.

    The following conditions shall be met for the use of overlay2 storage driver:

1, Pause the original container and export

Docker version update:

Pause all docker s, and export existing images and containers as tar packages

Export container

docker export  container id  -o  d.tar

Export image

docker  image  save  container  -o  a.tar

2, Remove the original Docker and install the new version

Remove the old version of Docker

 yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

Install a new version of Docker

# Yum utils provides the commands Yum config manager, device mapper persistent data and lvm2, which are used to store drivers.
yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
# Set yum source to stable version  
# Alibaba's source is used faster in China
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Official source (relatively slow in domestic use) 
yum-config-manager --add-repo    https://download.docker.com/linux/centos/docker-ce.repo
# Generate cache
yum makecache
# If you want to install the specified version
yum list docker-ce --showduplicates | sort -r
# Fill in the version number to the following command (docker-ce-19.03.0-3.el7)
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

# Install the latest stable version of Docker CE 
yum install docker-ce docker-ce-cli containerd.io    

3, Use the original data directory, or create a new data directory.

Use the original data directory

Use the previous data directory, that is, the previous version of the data directory, so that the previous images and containers can be imported directly.

Specify the previous storage directory. The storage directory of our former Docker is / opt/docker

cat << EOF >>/etc/docker/daemon.json
{
    "data-root": "/opt/docker"
}
EOF

Start docker

systemctl  start  docker
docker  images   # We can see that all the previous images exist
docker  info   # We can see

What changed after the update

  • journal before log driver now logfile

    Data directory:

[root@iz23nb5ujp69 docker]# ls -l
total 48
drwx------ 2 root root 4096 Aug  6 15:58 builder
drwx------ 4 root root 4096 Aug  6 15:58 buildkit
drwxrwxrwx 5 root root 4096 Aug  6 16:31 containers
drwxrwxrwx 5 root root 4096 Oct 13  2016 devicemapper
drwxrwxrwx 3 root root 4096 Oct 13  2016 image
drwxrwxrwx 3 root root 4096 Oct 13  2016 network
drwx------ 4 root root 4096 Aug  6 15:58 plugins
drwx------ 2 root root 4096 Aug  6 16:41 runtimes
drwx------ 2 root root 4096 Aug  6 15:58 swarm
drwx------ 2 root root 4096 Aug  6 16:41 tmp
drwxrwxrwx 2 root root 4096 Oct 13  2016 trust
drwxrwxrwx 2 root root 4096 Aug  6 15:58 volumes

The original version 1.10 is the default driver of devicemapper. If you use the Docker directory of the previous version, the default driver of the previous version will be used (for compatibility). If you use a new directory, the default storage driver and log engine of the official current version will be used.

Create new directory, import image

Use the new data directory / opt / docker CE.

cat << EOF >>/etc/docker/daemon.json
{
    "data-root": "/opt/docker-ce"
}
EOF
systemctl restart  docker 

Import image

docker image import  jenkins.tar    fy:jenkins

The imported image will use the default driver of Docker, that is, overlay2, and the default log driver. No matter what driver the original image uses, the current default storage driver will be used after importing.

4, Problems encountered during update

We follow the steps above to update, using the method of creating a new directory. When we start our Jenkins container and execute the build, we find the following error.

Problems after upgrade. Delete folder error. There is no problem with the command.

When entering the container, I execute the following command, which also reports an error.

[root@491c264aea0d target]# rm -rf  ./*
rm: cannot remove `./classes/com/ugou88/wx/interceptor': Invalid argument
rm: cannot remove `./classes/com/ugou88/wx/i/controller': Invalid argument

The problem, most likely caused by the driver, is the storage driver.

After upgrading, the default driver for Docker is overlay2. If you want to use this driver, you need to meet the following conditions.

  • overlay2`Docker CE and Docker EE 17.06.02-ee5 and later support this driver, which is the recommended storage driver.

  • Linux kernel version 4.0 or higher or RHEL/CentOs version number greater than 3.10.0-514 is required.

  • xfs file system is supported in the overlay and overlay 2 drivers, but it needs to be enabled with d_type=true.

    Use xfs? Info to verify that the ftype option is set to 1. To xfs format the file system correctly, use the flag - n ftype=1.

The version of Docker is also higher than 17.06.02 for our ext4 file system, but the version number of Centos is lower than 3.10.0-514, so I guess it's because the version number is too low, so the storage driver can't be used. After taking a snapshot of the system, we upgrade the kernel.

After upgrading the kernel, we restart the host and find that it can be used normally.

Topics: Docker yum CentOS Linux