linux_wiki:docker

Docker

General Information

Installing and configuring docker.

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 updated
    sudo yum update
  • Add the Docker repo
    • Repo
      yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    • Add the GPG key
      rpm --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 volume
    sudo 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 up
    systemctl daemon-reload

Docker: Start and Test

  • Start the Docker engine, enable on boot, and check status
    sudo systemctl start docker
    sudo systemctl enable docker
    sudo systemctl status docker
  • Verify docker was started with the correct options
    ps -elf | grep docker | grep -v grep
  • Run the test image to ensure it is installed correctly
    sudo docker run hello-world
  • Create the “docker” group and add users to it
    sudo usermod -aG docker <username>
    • Multiple users example
      for 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 sudo
    docker 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.

The Fix

  • Stop docker
    systemctl stop docker
  • Remove the docker thin pool logical volume
    lvremove /dev/vglocal/lvdockerpool
  • Re-create it (example using 100% of /dev/sde1)
    lvcreate --extents 100%PVS --thin --name lvdockerpool vglocal /dev/sde1

  • linux_wiki/docker.txt
  • Last modified: 2019/07/20 18:13
  • by billdozor