3.7 Additional commands

  • docker inspect: Get details from containers (both running and stopped). Things such as IPs, volumes, etc.

  • docker logs: Get console messages from running containers. Useful when using with web services.

  • docker commit: Turn a container into an image. It make senses to use when modifying container interactively. However this is bad for reproducibility if no steps are saved.

Good for long-term reproducibility and for critical production environments:

  • docker save: Save an image into an image tar archive.

  • docker load: Load an image tar archive to become an image.

  • docker export: Save a container filesystem into a tar archive.

  • docker import: Import a filesystem tar archive into an image (you need to specify a target tag).

HANDS-ON

  • Save a previously created image into a tar archive (Look at the command’s options for help). Remove the original image and recover it again.
Answer

# Let's save the image in a tar
docker save -o random_numbers.tar random_numbers_${USER}

# Remove the original image
docker rmi random_numbers_${USER}

# Check existing images now
docker images

# Recover it
docker load < random_numbers.tar

# Check now images
docker images
If you check the tar archives generated thanks to save with the ones using export, you will notice they do not look the same. The former ones ressemble more what you will find in /var/lib/docker (that is where Docker daemon stores its data) and it includes metadata information (so it is not necessary to specify an image tag). On the other hand, tar files generated with export they simply contantain the image filesystem. You lost that way a lot of metadata associated to the original image, such as the tags, but also things such as ENTRYPOINT and CMD instructions.