5.19 Committing, Exporting and Importing Images

You can use the docker commit command to save the current state of a container to an image.

# docker commit \
  [--author="name"] \
  [--change="instructions"]... \
  [--message="text"] \
  [--pause=false] container [repository[:tag] 

You can use this image to create new containers, for example to debug the container independently of the existing container.

You can use the docker export command to export a container to another system as an image tar file.

# docker export [--output="filename"] container
Note

You need to export separately any data volumes that the container uses. See Section 5.10, “Moving Data Between Docker Containers and the Host”.

To import the image tar file, use docker import and specify the image URL or read the file from the standard input.

# docker import [--change="instructions"]... URL [repository[:tag]
# docker import [--change="instructions"]... - [repository[:tag] < filename

You can use --change options with docker commit and docker import to specify Dockerfile instructions that modify the configuration of the image, for example:

# docker commit --change "LABEL com.mydom.status='Debug'" 7ac15076dcc1 mymod/debugimage:v1

For docker commit, you can specify the following instructions: ADD, CMD, COPY, ENTRYPOINT, ENV, EXPOSE, FROM, LABEL, MAINTAINER, RUN, USER, VOLUME, and WORKDIR.

For docker import, you can specify the following instructions: CMD, ENTRYPOINT, ENV, EXPOSE, ONBUILD, USER, VOLUME, and WORKDIR.