Managing Storage with Docker Formatted Containers on Red Hat Enterprise Linux and Red Hat Enterprise Linux Atomic Host
Request a new translation or translation update
A translation for your language preference does not exist. Click below to request a translation for your selected language.
Table of Contents
- Overview
- Configuring docker-storage-setup
- Managing Storage in Red Hat Enterprise Linux
- Managing Storage in Red Hat Enterprise Linux Atomic Host
- Changing Docker Storage Configuration
- Additional Information About Storage
Overview
Docker needs storage to store containers and container images. The default storage option for Docker on Red Hat Enterprise Linux Atomic Host is an LVM thin pool while the default option on other variants of Red Hat Enterprise Linux is thin pool on loopback devices which is not recommended for production systems. The docker-storage-setup service can assist you in setting up an LVM thin pool.
When docker starts, it automatically starts docker-storage-setup. By default, docker-storage-setup tries to find free space in the volume group backing the root volume and tries to setup a thin pool. If there is no free space in the volume group, docker-storage-setup will fail to set up an LVM thin pool and will fall back to using loopback devices.
Configuring docker-storage-setup
There are many options provided to control the behavior of docker-storage-setup. The default behavior is controlled by the /usr/lib/docker-storage-setup/docker-storage-setup configuration file. You can override these options by creating a file /etc/sysconfig/docker-storage-setup and override any of the configuration options using new values. See man docker-storage-setup(1) for more information.
docker-storage-setup needs to know where is the free space to set up a thin pool. Following are some of the ways you can configure the system to make sure docker-storage-setup can setup an LVM thin pool.
LVM thin pool in volume group backing root volume
By default, docker-storage-setup looks for free space in the root volume group and creates an LVM thin pool. Hence you can leave free space during system installation in the root volume group and starting docker will automatically setup thin pool and use it.
LVM thin pool in a user specified volume group
docker-storage-setup can be pointed to a volume group which should be used for creating a thin pool.
# echo VG=docker-vg >> /etc/sysconfig/docker-storage-setup
# systemctl start docker
Setting up volume group and LVM thin pool on user specified block device
One can specify a block device or devices to docker-storage-setup and it will create a
volume group and carve out a lvm thin pool for docker use.
# echo DEVS=/dev/vdb >> /etc/sysconfig/docker-storage-setup
# systemctl start docker
Managing Storage in Red Hat Enterprise Linux
In Red Hat Enterprise Linux, there is no free space in the root volume group by default. So one has to take some steps to make sure docker-storage-setup can find free space.
One easy way is to leave some free space in volume group containing root, during installation. Following section explains how to leave free space.
How to Leave Space in the Volume Group Backing Root During Installation
Primarily there are two methods to leave free space in the root volume group. You can use the interactive graphical installation (Anaconda) or a Kickstart file to control the installation.
GUI Installation
-
Start the graphical installation; when you arrive at the "Installation Destination" screen, select "I will configure partitioning" from "Other Storage Options" and click "Done".
-
On the "Manual Partitioning" screen, where you are prompted to create mount points. Choose "Click here to create them automatically". This will create the default partitioning scheme.
-
Choose the root partition (/) , this is show the "Desired Capacity" input field.
-
Reduce that capacity to leave some free space in the root volume group.
-
By default, the volume group which has the root LV is big enough to accomodate user-created volumes. Any free space on disk is left free and is not part of that volume group. Change that by clicking on "Modify" and selecting "Size policy" as "As large as possible". Click "Save". This makes sure that any unused space on disk is left free in the volume group.
-
Click "Done", accept the proposed partitioning
-
Click "Begin Installation"
Kickstart Installation
In a Kickstart file, use the "volgroup" Kickstart option with the "--reserved-percent" and "--reserved-space" options where you can specify how much space to leave free in volume group. Here is an example section of a Kickstart file which leaves 20% free space in the root LV:
# Disk partitioning information
part /boot --size=500
part pv.1 --size=500 --grow
volgroup rhel --pesize=4096 pv.1 --reserved-percent=20
logvol / --size=500 --grow --name=root --vgname=rhel
logvol swap --size=2048 --name=swap --vgname=rhel
Managing Storage in Red Hat Enterprise Linux Atomic Host
On Red Hat Enterprise Linux Atomic Host, the root volume size is 3GB. There is free space in the root volume group and 60% of that is used by docker-storage-setup for setting up an LVM thin pool. Rest of the space is free and can be used for extending the root volume or for creating a thin pool.
On RHEL Atomic Host with default partitioning setup, the docker-storage-setup service creates an LVM thin pool to be used by the container images. During installation, the installation program creates the root Logical Volume that is 3GB by default. Next, during boot, the docker-storage-setup service automatically sets up an LVM thin pool called docker-pool which takes 60% of the remaining space. The rest can be used for extending root or docker-pool.During boot, docker-storage-setup reads the /etc/sysconfig/docker-storage file to determine the type of storage used and it modifies it so that docker makes use of the LVM thin pool. You can override the defaults by creating a file called /etc/sysconfig/docker-storage-setup which will modify the behavior of the service during boot. If you do not create such file, then an LVM thin pool will be created by default.
Red Hat Enterprise Linux Atomic Host installed from a cloud image with default partitioning has a Volume Group called atomicos and two Logical Volumes as part of that group. The name of the Volume Group varies between different images of Red Hat Enterprise Linux Atomic Host. For bare-metal and virtual installations the Volume Group name is derived from the host name. If the host is unnamed, the Volume Group will be called rah. The properties of the Volume Group and the Logical Volumes in them are the same across all images.
You can run the lvs command to list the Logical Volumes on the system and see the Volume Group name:
# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
docker-pool atomicos twi-aotz-- 7.69g 14.36 2.56
root atomicos -wi-ao---- 2.94g
-
The "Root partition" is called root and is 3GB by default. root is a Logical Volume that contains the following:
-
The /var and /etc directories.
-
The /ostree/repo which contains the OSTree versions.
-
The /var/lib/docker/ directory which contains container images data, such as temporary data or the docker volumes. A docker volume is a unit of storage that a running container can request from the host system. The unit of storage can be provided by another container but also by the host directly. In the case of Red Hat Enterprise Linux Atomic Host, these volumes are automatically allocated to the Root Partition, in /var/lib/docker/vfs/.
-
-
A Container Image Partition called docker-pool which takes all remaining space. It is formatted as an LVM thin pool by the docker-storage-setup service. It is used to store the container images. The space of docker-pool is managed by the docker-storage-setup service. When you pull a container image from a registry, for example, the image takes up space on this partition. Container images are read-only. Once an image is launched as a container, all writes (except to mounted volumes or docker volumes) are stored in this Logical Volume.
It is very important to monitor the free space in docker-pool and not to allow it to run out of space. If the LVM thin pool runs out of space it could expose the user to failure modes because the XFS file system which consumes the LVM thin pool will be retrying indefinitely in response to any I/O errors. The LVM2 tools provide facility to monitor a thin pool and extend it based on user settings. See the Automatically extend thin pool LV and Data space exhaustion sections of the lvmthin(7) manual page for more information. By default, docker-storage-setup configures the thin pool for auto extension. This means as the pool fills up, it will automatically grow and consume free space available in that volume group. If volume group gets full and there is no space left for auto extension, then you can preemptively destroy old containers that are no longer needed to reclaim space. Or you can stop creating or modifying container images until additional storage is added to the system.
-
/etc/sysconfig/docker - managed by humans
-
/etc/sysconfig/docker-storage-setup - managed by humans
-
/etc/sysconfig/docker-storage - managed by programs, but can be written by humans (you have to disable docker-storage-setup)-->
Changing the Default Size of the Root Partition During Installation
To change the default Root Partition size, use the method below for your installation.
-
Anaconda: When you arrive at the "Installation Destination" screen, select "I will configure partitioning" from "Other Storage Options" and click "Done". This will lead you to the "Manual Partitioning" screen, where you are prompted to create mount points. Choose "Click here to create them automatically", which will give you the boot, root, and swap partitions. (At this point, you only have these partitions, docker-pool is created later by the docker-storage-setup service). Choose the root partition (/) and enter the new value in the "Desired Capacity" input field. When you finish the installation, the system boots with your custom configuration.
-
Kickstart: In the %post section of the Kickstart file, point to the /etc/sysconfig/docker-storage-setup file (which will be created automatically) and specify the necessary options after the command. The syntax is as follows:
%post
cat > /etc/sysconfig/docker-storage-setup << EOF
ROOT_SIZE=6G
EOF
- cloud-init: The write_files directive in the user-data file is used to setup the /etc/sysconfig/docker-storage-setup file similarly to the Kickstart example above. This example user-data file sets the password for cloud-user to "atomic" and configures the root partition to be 6GB instead of the default 3GB.
#cloud-config
password: atomic
write_files:
- path: /etc/sysconfig/docker-storage-setup
permissions: 0644
owner: root
content: |
ROOT_SIZE=6G
For more information about using cloud-init, see the Frequently Asked Questions about cloud-init article.
Changing the Size of the Root Partition After Installation
When you add container images to the Container Image Partition which require space in /var/lib/docker/, the image can request more space than it is currently available on the Root Partition. A container image can request a docker volume when it has data that should not be stored in the container, for example the data from a database server. If you run out of space on root, you have three options:
-
Extend the Root Partition to use the free space in the volume group.
-
Add new storage to the host and extend the Root Partition.
-
Extend the Root Partition and shrink the Container Image Partition.
How to extend the Root Partition to use free space in volume group
If there is free space in volume group, then one can simple extend root volume to use some or all of that free space and grow the root partition.
# lvextend -r -L +3GB /dev/atomicos/root
How to Add Additional Storage to the Host and Extend the Root Partition
This option is non-destructive and will allow you to simply add more storage to the Root Partition and use it. You will need to create a new Physical Volume using a new disk device (in this example /dev/sdb), add it to atomicos Volume Group and then extend the Root Partition Logical Volume. You will have to stop the docker daemon and the docker-storage-setup service for this task. Use the following commands:
# systemctl stop docker docker-storage-setup
# pvcreate /dev/sdb
# vgextend atomicos /dev/sdb
# lvextend -r -L +3GB /dev/atomicos/root
# systemctl start docker docker-storage-setup
How to Extend the Root Partition Without Adding More Storage
This option is destructive because the Container Image Partition will be destroyed. If it is not possible to add more storage to the Root Partition, you can extend it. Extending the Root Partition means that you will have to shrink the Container Image Partition. LVM does not support shrinking Thinly-Provisioned Logical Volumes. Therefore, you will have to stop all running containers, destroy the Container Image Partition, and extend the Root Partition. docker-storage-setup will reallocate the remaining space to the Container Image Partition when it is restarted. Use the following commands:
# systemctl stop docker docker-storage-setup
# rm -rf /var/lib/docker/*
# lvm lvremove atomicos/docker-pool
# lvextend -L +3GB /dev/atomicos/root
# systemctl start docker-storage-setup
# systemctl start docker
At this point you will need to download all your container images again.
Changing Docker Storage Configuration
If you change the storage configuration of Docker, you must also remember to remove the /var/lib/docker directory. This directory contains the metadata for old images, containers and volumes which are not valid for the new configuration. Examples of instances in which you might change the storage configuration include when you switch from using loop devices to LVM thin pool or if you switch from one thin pool to another. In the later case, you should also remove the old thin pool.
# systemctl stop docker
# Edit /etc/sysconfig/docker-storage-setup
# Remove old thin pool logical volume (lvremove docker/docker-pool)
# rm -rf /var/lib/docker/
# systemctl start docker
Additional Information About Storage
-
The Thinly-Provisioned Logical Volumes section from the LVM Administrator Guide explains LVM Thin Provisioning in detail.
-
The Red Hat Enterprise Linux 7 Storage Administration Guide guide provides information on adding storage to Red Hat Enterprise Linux 7.
This solution is part of Red Hat's fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.