Docker configures the storage location of local images and containers

Docker configures the storage location of local images and containers

Use the find command to find files larger than a specified size:

 find / -type f -size +10G

Exclude a directory

find / -path "/media/xww" -type f -size +10G

How to modify the storage location of Docker local images and containers

Method 1: Soft link

By default, Docker is stored in: /var/lib/docker
You can view the specific location by running the following command:

sudo docker info | grep "Docker Root Dir"

The most direct way to solve this problem is of course to mount the partition to this directory, but my data disk has other things, which is definitely not easy to manage, so I use the method of modifying the storage path of the image and container to achieve the goal.

This method will be implemented through soft connection.

First stop the Docker service:

systemctl restart docker
Or service docker stop

Then move the entire /var/lib/docker directory to the destination path:

mv /var/lib/docker /root/data/docker
ln -s /root/data/docker /var/lib/docker

At this time, when you start Docker, you will find that the storage directory is still /var/lib/docker, but it is actually stored on the data disk. You can see the capacity changes on the data disk.

Method 2: Expandable logical volume

By default, the docker storage location is:
/var/lib/docker
Generally, we don't make the root partition too large. There are generally two solutions for storing more and more images and containers
1. Mount the large partition to /var/lib/docker:
Generally, it is chosen to create a logical partition lvm to facilitate the subsequent expansion of the group.

a. Create a new partition and format it. PS: The following operations assume that you already have an existing volume group and can directly create a logical volume. Or you can create a logical volume yourself, or use partitions directly without using logical volumes: lvcreate -L 300G lv_docker vg_home  
mkfs.ext4 /dev/vg_home/lv__docker  
    b. Mount the new partition to the temporary mount point [plain] view plain copy
mkdir /mnt/docker  
mount /dev/vg_home/lv_docker /mnt/docker/ 

    c. After stopping docker, copy the data under /var/lib/docker to the temporary mount point [plain] view plain copy
service docker stop  
cp -r /var/lib/docker/* /mtn/docker 

    d. Modify /var/lib/docker to //var/lib/docker.bak and create /var/lib/docker
[plain] view plain copy
mv /var/lib/docker{,.bak}  
mkdir /var/lib/docker 

    e. Mount the new partition to /var/lib/docker and set it to mount automatically at boot.
[plain] view plain copy
mount /dev/vg_home/lv_docker /var/lib/docker  
vim /etc/fstab  
---  
 /dev/vg_home/lv_docker /docker_data ext4 defaults 0 0  
----  

     f. Check whether docker is available and whether the data is complete [plain] view plain copy
docker images  
docker ps -a  

     g. After confirmation, uninstall the temporary mount point and delete /var/lib/docker.bak
[plain] view plain copy
umount /mnt/docker  
rm -rf /var/lib/docker.bak

Method 3: Modify the storage path of images and containers

The parameter for specifying the image and container storage path is –graph=/var/lib/docker. We only need to modify the configuration file to specify the startup parameters.

The Docker configuration file can set most of the background process parameters. The storage location in each operating system is different. The location in Ubuntu is: /etc/default/docker, and the location in CentOS is: /etc/sysconfig/docker.

If it is CentOS, add the following line:

OPTIONS=--graph="/root/data/docker" --selinux-enabled -H fd://

If it is Ubuntu, add the following line (because Ubuntu does not enable selinux by default):

OPTIONS=--graph="/root/data/docker" -H fd://
# or DOCKER_OPTS="-g /root/data/docker"

Finally, restart and the Docker path will be changed to /root/data/docker.
If it does not work, do the following:

vim /etc/default/docker  
Add configuration information DOCKER_OPTS="--graph=/home/docker"  
Save and exit service docker restart  
Found that the configuration did not take effect solution:
 mkdir -p /etc/systemd/system/docker.service.d  
 cat /etc/systemd/system/docker.service.d/Using_Environment_File.conf  
If the file does not exist, create it yourself and add the following content [Service]  
EnvironmentFile=-/etc/default/docker  
ExecStart=  
ExecStart=/usr/bin/docker daemon -H fd:// $DOCKER_OPTS  
Load configuration and restart service systemctl daemon-reload  
service docker restart  
Check whether the configuration is effective

This is the end of this article about Docker configuration of local images and container storage locations. For more information about Docker configuration of local images and container storage locations, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker container explains in detail how to simplify the image and reduce the size
  • Docker generates images through containers and submits DockerCommit in detail
  • Skywalking containerized deployment of docker images to build k8s from testing to availability
  • Implementation of IDEA remote management of docker images and container services
  • Docker container practice image warehouse
  • Docker container practice: how images and containers work

<<:  Summary of basic operations for MySQL beginners

>>:  Comparing Document Locations

Recommend

JavaScript to achieve a simple countdown effect

This article example shares the specific code of ...

javascript input image upload and preview, FileReader preview image

FileReader is an important API for front-end file...

JavaScript quickly implements calendar effects

This article example shares the specific code of ...

Install mysql 5.6 from yum source in centos7.4 system

System environment: centos7.4 1. Check whether th...

Introduction to MySQL overall architecture

The overall architecture of MySQL is divided into...

vue-cli configuration uses Vuex's full process record

Table of contents Preface Installation and Usage ...

How to use an image button as a reset form button

When we make a form, we often set a submit button ...

VMware 15.5 version installation Windows_Server_2008_R2 system tutorial diagram

1. Create a new virtual machine from VMware 15.5 ...

Vue implements an Input component that gets the key display shortcut key effect

I encountered a requirement to customize shortcut...

How to modify the default submission method of the form

The default submission method of html is get inste...

Node.js sends emails based on STMP protocol and EWS protocol

Table of contents 1 Node.js method of sending ema...

The best way to start a jar package project under Centos7 server

Preface Everyone knows how to run a jar package o...

Sharing ideas on processing tens of millions of data in a single MySQL table

Table of contents Project Background Improvement ...

JavaScript recursion detailed

Table of contents 1. What is recursion? 2. Solve ...