Author Carpentry logo

Transfering and archiving Docker containers

10 Minutes


Learning Objectives


Recap: Image vs. container

An image is a blueprint for a container. A container is an instance of an image. A container can divert from the image during its lifetime.

Save a Docker image

docker save --output articles-wordcloud.tar authorcarpentry-docker-articles
ls *.tar

We use the --output option to save the image to a file.

You can learn more about the save command on Docker Docs.

What does this mean for reproducible research?

Images are nice because there is a dual relationship between the Dockerfile used to build the image and the image itself. However, it requires additional work to create a matching image when you work inside the container.

Export a container

If you choose to manually manipulate a container, or include results of some processing, then you will export a container.

# find out the container ID
docker ps -a

docker save --output articles-wordcloud.tar authorcarpentry-docker-articles
ls *.tar
tar -tvf articles-wordcloud.tar

You can learn more about the export command on Docker Docs.

What does this mean for reproducible research?

You should be careful when exporting containers, because you lack the metadata/documentation of the Dockerfile.

Labels for images and containers

Docker provides labels to add custom metadata to images and containers. You can use it to provide information that helps you and others to

We can add labels to images by using the LABEL instructions in the Dockerfile.

FROM rocker/rstudio

LABEL name=my_image_for_research \
    author=Daniel

We can add labels when starting a container.

$ docker run -it --label experiment_run_numer=42 authorcarpentry-docker-articles

# find out container name
docker ps -a

# print out the label using inspect
docker inspect jolly_euclid | grep experiment

These labels will still be there after exporting and importing.

You can learn more about labelling and custom metadata in the Docker docs and about the inspect command.

Archiving a Docker image or container

You can now upload the tarball to a data repository, such as figshare or Zenodo, get a DOI and cite it in your work.