[Linux]-docker Modify space size

Source: Internet
Author: User
Tags docker run

Docker default space size is divided into two, one is the pool space size, the other is the container space size.

The pool space size defaults to: 100G

Container space size is assumed to be: 10G

So the size of the modified space is also divided into two:

This is used by the Yum under CentOS to install Docker.

First, to modify the size of the space, you must make Docker run in the daemon environment, that is, stop the running Docker service first:

Service Docker stop

Then use the command to run Docker using the daemon environment:

Docker-d

One, modify the pool space size method:

DD if=/dev/zero of=/var/lib/docker/devicemapper/devicemapper/data bs=1g count=0 seek= DD if=/dev/zero of=/var/lib/docker/devicemapper/devicemapper/metadata bs=1g count=0 seek=10 

The above 1000 is 1TB size, that is, the data pool space size is 1TB, and 10 is the space size of metadata, 10GB

When you are finished running, use the command to view the size of the Docker pool space:

Info

You can see that the pool space has been set to DATA=1TB and METADATA=10GB

Second, modify the size of the container space:

1. First enter the directory (use Yum to install Docker's default directory):

cd/dev/mapper/

2. Use the command to see if the container is running.

PS -A

Here you can see that the container test is running.

3. Use the command to view the container volume:

Dmsetup table

Can see 20971520, this is the volume space value, we need to modify is here.

Other values to note: 253:7 11

4. Use the LS or LL command to see if the file exists in the/dev/mapper/directory. (This step is important because the non-running container will not have this file)

5. Use the command to modify the container space size:

Echo 0 88080384 253:7 | Dmsetup load docker-253:1-184549824- 95f242e4fe2fef132ab1a706ebf8eecbb1c6db19547c3f12b34b76a5dee96c7e

Here 88080384 will replace the original 20971520 value, meaning: 42GB.

The counting formula is: 42*1024*1024*1024/512

You can print using the command:

Echo $ ((* * 1024x768/1024x768)

Then use the command:

Dmsetup Resume docker-253:1-184549824-/dev/mapper/docker-253:1 -184549824-95f242e4fe2fef132ab1a706ebf8eecbb1c6db19547c3f12b34b76a5dee96c7e

Complete.

Then go to the container terminal and use the command df-h to see the modified container space:

Wrote a shell script to modify the pool, container space use:

1, resize_docker.sh

#!/bin/bashdata_size=$1metadata_size=$2if["$DATA _size"=""]; Thendata_size= +fiif["$METADATA _size"=""]; Thenmetadata_size=Tenfi# Stop Docker servicesystemctl stop docker# Resize Docker data SpaceDD if=/dev/zero Of=/var/lib/docker/devicemapper/devicemapper/data bs=1g count=0seek=$DATA _size# Resize Docker metadata SpaceDD if=/dev/zero Of=/var/lib/docker/devicemapper/devicemapper/metadata bs=1g count=0seek=$METADATA _size# start Docker servicesystemctl start Docker

To run the script method:

sh resize_docker. SH  + Ten

Will change Docker's pool to DATA=1TB,METADATA=10GB

2, resize_container.sh

#!/bin/Bashcid=$1SIZE=$2if["$CID"!=""] && ["$SIZE"!=""]; ThenDEV=$(basename$(Echo/dev/mapper/docker-*-$CID)); Dmsetup Table $DEV|sed "s/0 [0-9]* thin/0 $ (($SIZE *1024*1024*1024/512)) thin/"|dmsetup load $DEV;    Dmsetup Resume $DEV; RESIZE2FS/dev/mapper/$DEV; Echo "Resize $CID completed."Else    Echo "usage:sh Resize_container 459fd505311ad364309940ac24dcdb2bdfc68e3c3b0f291c9153fb54fbd46771";fi

To run the script method:

sh resize_container. SH  -

Change the space of the container 459fd505311ad364309940ac24dcdb2bdfc68e3c3b0f291c9153fb54fbd46771 to 100GB

Note: Modifying the space must be done in Docker's daemon mode.

Reference documents:

http://segmentfault.com/a/1190000002931564

[Linux]-docker Modify space size

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.