Use export and import to export and import docker containers

  • 2020-06-19 12:08:59
  • OfStack

This article introduces the use of export/import export and import docker containers, to share with you, the details are as follows:

1. Export the container

If you want to export a container locally, you can use the docker export command to export the container snapshot to a local file.


$ 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

2. Import container snapshot

You can use docker import to re-import the image from the container snapshot file, 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

Alternatively, you can import by specifying URL or a directory, for example


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

* Note: Users can use docker load to import the image storage file to the local image library, or docker import to import 1 container snapshot to the local image library. The difference between the two is that the container snapshot file will discard all history and metadata information (that is, only the snapshot state of the container at the time), while the mirror storage file will hold the full record and be bulky. In addition, metadata information such as labels can be re-specified when importing from a container snapshot file.


Related articles: