Docker

Installation

  1. Enable repo:subscription-manager repos --enable=rhel-7-server-extras-rpms

  2. Install the package: yum install docker

  3. Activate IP forward

vi /etc/sysctl.conf

net.ipv4.ip_forward = 1

Configure LVM thin pool

pvcreate /dev/sdb
vgcreate vgdocker /dev/sdb

vi /etc/sysconfig/docker-storage-setup

CONTAINER_THINPOOL=docker-pool
VG=vgdocker
SETUP_LVM_THIN_POOL=yes
DATA_SIZE=100%FREE

docker-storage-setup

If docker has already been started before that remove the /var/lib/docker content

systemctl stop docker
rm -rf /var/lib/docker/*
systemctl start docker

Commands

To detach the tty without exiting the shell, use the escape sequence Ctrl-p + Ctrl-q

  • List running containers: docker ps
  • List all containers: docker ps -a
  • List images: docker images
  • Return low-level information on a container or image: docker inspect <container id> or docker inspect <image>
  • Lookup the running processes of a container: docker top <container id>
  • Fetch the logs of a container (only for the json-file and journald logging) : docker logs <container id>
  • Attach to a running container (docker exec -it /bin/bash if if docker attach fails): docker attach <container id>
  • Start a container: docker start <container id>
  • Stop a container: docker stop <container id>
  • Restart a container: docker restart <container id>
  • Remove one or more containers: docker rm <container id>
  • Run a command in a new container: docker run -i -t centos /bin/bash
  • Copy files/folders between a container and the local filesystem: docker cp 'aa602111a6b7':/etc/fstab .
  • Delete all containers: docker rm $(docker ps -a -q)
  • Delete all images: docker rmi $(docker images -q)
  • List unused volumes: docker volume ls -qf dangling=true
  • Removing orphaned Docker volumes: docker volume rm $(docker volume ls -qf dangling=true)
  • Find out logging type (Red Hat - journal & Docker - json): docker info |grep Logging
  • Committing changes to an image: docker commit <container id> image_name
  • Push image: docker push username/image_name
  • Display data and meta devices: lvs -a
  • Shows logs in real time: journalctl -fu docker.service
  • See what's inside a container: docker export <container id> | tar -t
  • Search after bash location: docker export <container id> | tar -t | egrep ^bin/bash

Important files

  • Default configuration: /usr/share/container-storage-setup/container-storage-setup
  • Storage configuration file (automatically updated by docker-storage-setup command): /etc/sysconfig/docker-storage
  • Override the default configuration: /etc/sysconfig/docker-storage-setup
  • Docker daemon options: /lib/systemd/system/docker.service
  • Change the way the docker daemon will start ($OPTIONS from /lib/systemd/system/docker.service): /etc/sysconfig/docker

Links