export container
If you want to export a local container, you can use docker export
the command.
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7691a814370e ubuntu:18.04 "/bin/bash" 36 hours ago Exited (0) 21 hours ago test
$ docker export 7691a814370e > ubuntu.tar
This will export the container snapshot to a local file.
Import container snapshot
docker import
Reimport as an image from a container snapshot file can be used , e.g.
$ cat ubuntu.tar | docker import - test/ubuntu:v1.0
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
test/ubuntu v1.0 9d37a6082e97 About a minute ago 171.3 MB
In addition, you can also import by specifying a URL or a directory, for example
$ docker import http://example.com/exampleimage.tgz example/imagerepo
Note: Users can either use docker load to import image storage files to the local image library, or use docker import to import a container snapshot to the local image library. The difference between the two is that the container snapshot file will discard all historical records and metadata information (that is, only save the snapshot state of the container at that time), while the image storage file will save a complete record, and the volume is also large. In addition, metadata information such as tags can be re-specified when importing from a container snapshot file.
link: https://yeasy.gitbook.io/docker_practice/container/import_export