Docker

Cleanup

Source

Old containers can be removed all at once:

# Containers used hours,weeks or months ago
$ docker ps -a | egrep '(hours|weeks|months) ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm

# All containers
$ docker rm $(docker ps -a -q)

Old Images: Source

# All images
$ docker rmi $(docker images -q)

# Untagged images
$ docker rmi $(docker images | grep "^<none>" | awk "{print $3}")

Check for experimental feature

Source

docker version -f '{{ .Server.Experimental }}'

Error

Registry Endpoint

Source

  • Description: When running docker pull <imagename>, the following error message appears:
...

Could not reach any registry endpoint
  • Solution: This can have two reasons. Docker tries to download automatically the tag 'latest'. If that is not available, this can come up as error. Second: The installed docker version can be too old to play harmonously with the hub. Upgrade the docker version. This error has been seen at version 1.4 and 1.5 already.

Docker CentOS7

Source

Errormessage:

/usr/bin/docker: relocation error: /usr/bin/docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference

Solution:

sudo yum install device-mapper-devel

Alternative: Update to the latest version with

sudo yum update

DeleteDevice

Source Error:

Unable to delete device: Error running DeleteDevice dm_task_run failed

Solution:

Ran full of disk space the first time, he? Well, happened to me as well. Reboot does not fix this. When filling up the disk, some garbage is left that prevents docker from starting now.

Just delete /var/lib/docker and try again (migh want to save something?)

sudo rm -rf /var/lib/docker

docker build

Environment variables during build

docker build [...] --build-arg VARIABLE=value

Conditional copy of files

Source

This example from a Dockerfile runs the COPY command in dependency of an environment variable being set. This example is based on using the alpine docker image.

ARG BUILD_ENV=copy

FROM alpine as build_copy
ONBUILD COPY file /file

FROM alpine as build_no_copy
ONBUILD RUN echo "I don't copy anythin."

FROM build_${BUILD_ENV}
# other stuff