====== Docker ====== **General Information** Installing and configuring docker. * **Docker Versions Change Log** - Change branches to see different change logs * 17.12: https://github.com/docker/docker-ce/blob/17.12/CHANGELOG.md **Checklist** * CentOS 7 ---- ====== Docker: Upgrade to CE ====== Docker has switched from docker-engine packages to docker-ce (community edition) and docker-ee (enterprise edition). docker-engine-ce's last version was 17.05. Official documentation: https://docs.docker.com/engine/installation/linux/docker-ce/centos/ ---- ====== Docker: Install ====== * Ensure system is updatedsudo yum update * Add the Docker repo * Repoyum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo * Add the GPG keyrpm --import https://download.docker.com/linux/centos/gpg * Install Docker * CE (community edition)yum install docker-ce ---- ====== Docker: Storage ====== **Docker Data and Meta Data** * Create a "thin" logical volume using all of the space on a physical volumesudo lvcreate --extents 100%PVS --thin --name lvdockerpool vglocal /dev/sdX1 * This thin logical volume will be used by the docker daemon directly to automatically setup a file system and allocate space for docker data and metadata. * **NOTE:** This space is NOT used for docker container image storage. (/var is the default) \\ If you ever need to increase docker container data storage OR metadata storage, they can be resized individually. * Resize docker pool metadata example (increase by 1 GB)lvextend --size +1G -n vglocal/lvdockerpool_tmeta * Resize docker pool storage example (increase by 10 GB)lvextend --size +10G -n vglocal/lvdockerpool_tdata \\ **Docker container image storage (/var)** * If /var needs more space for container image storage, run the following (example)sudo lvextend --resizefs --size +7G /dev/vglocal/lvvar ---- ====== Docker: Service ====== **Service Setup** * Override default docker.service startup options * Create a systemd docker.service override directory sudo mkdir /etc/systemd/system/docker.service.d * Create a docker.service override file * **Docker 1.12 (2016-07-28) - 17.12.0-ce (2017-12)**tee /etc/systemd/system/docker.service.d/docker.conf <<-'EOF' [Service] EnvironmentFile= EnvironmentFile=-/etc/sysconfig/docker ExecStart= ExecStart=/usr/bin/dockerd $OPTIONS EOF * The blank variable setting ensures that no default settings are appended to the overrides. * Setup docker daemon startup options * **Docker 1.12 (2016-07-28) - 17.12.0-ce (2017-12)**tee /etc/sysconfig/docker <<-'EOF' # Modify these options if you want to change the way the docker daemon runs OPTIONS=--storage-driver=devicemapper --storage-opt dm.thinpooldev=vglocal-lvdockerpool --storage-opt dm.use_deferred_deletion=true --storage-opt dm.use_deferred_removal=true EOF * Reload the systemd daemon for the override file to be picked upsystemctl daemon-reload ---- ====== Docker: Start and Test ====== * Start the Docker engine, enable on boot, and check statussudo systemctl start docker sudo systemctl enable docker sudo systemctl status docker * Verify docker was started with the correct optionsps -elf | grep docker | grep -v grep * Run the test image to ensure it is installed correctlysudo docker run hello-world * Create the "docker" group and add users to itsudo usermod -aG docker * Multiple users examplefor x in user1 user2 user3; do sudo usermod -aG docker $x; done * Log out/log back in * Verify the user can run docker commands without using sudodocker run hello-world ---- ====== Troubleshooting ====== * **Symptom**: Docker service fails to start * **Error Seen In Logs**: Error starting daemon: error initializing graphdriver: devicemapper: Non existing device vglocal-lvdockerpool * **Why**: /var/lib/docker contains metadata telling docker about the contents of device mapper storage. When /var/lib/docker is removed, metadata is lost. Then docker will detect the thin pool has data, but docker is unable to use it. * **Official Documentation**: https://access.redhat.com/solutions/2281281 __**The Fix**__ * Stop dockersystemctl stop docker * Remove the docker thin pool logical volumelvremove /dev/vglocal/lvdockerpool * Re-create it (example using 100% of /dev/sde1)lvcreate --extents 100%PVS --thin --name lvdockerpool vglocal /dev/sde1 ----