Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Export and import Docker containers


May 22, 2021 Docker From entry to practice



Export the container

If you want to export a local container, you docker export command.

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES
7691a814370e        ubuntu:14.04        "/bin/bash"         36 hours ago        Exited (0) 21 hours ago                       test
$ sudo docker export 7691a814370e > ubuntu.tar

This exports the container snapshot to the local file.

Import a container snapshot

You docker import to import from a container snapshot file as a mirror, for example

$ cat ubuntu.tar | sudo docker import - test/ubuntu:v1.0
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              VIRTUAL SIZE
test/ubuntu         v1.0                9d37a6082e97        About a minute ago   171.3 MB

You can also import by specifying a URL or a directory, for example

$sudo docker import http://example.com/exampleimage.tgz example/imagerepo

Note: Users can neither docker load files to the local mirror library or docker import import a container snapshot to the local mirror library. T he difference between the two is that the container snapshot file discards all history and metadata information (that is, only the snapshot state of the container at the time), while the mirror storage file holds the full record and is larger. In addition, metadata information such as labels can be re-specified when importing from a container snapshot file.