reference
5 ways to move Docker container to another host
Build a Docker Image with MySQL Database
Plan A
Step1 create an Image From a Container
Create a new image from a container’s changes
1 | sudo docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] |
options
Name, shorthand Default Description --author
,-a
Author (e.g., “will brook”) --change
,-c
Apply Dockerfile instruction to the created image --message
,-m
Commit message --pause
,-p
true
Pause container during commit
Step 2 export the image to a file
1 | sudo docker save -o /path/to/your_image.tar your_image_name |
Step 3 load the Docker image file
1 | sudo docker load -i your_image.tar |
Plan B
Step 1
First save the new image by finding the container ID (using docker container ls
) and then committing it to a new image name. Note that only a-z0-9-_.
are allowed when naming images:
1 | create image from container |
Step 2
tag the image with the host name or IP address, and the port of the registry:
1 | re-tag repository:tag info about image |
Step 3
log in from Docker client:
1 | docker login <harbor_address> |
Step 4
push the image to the registry using the image ID.
In this example the registry is on host named registry-host
and listening on port 5000
. (harbor默认配置端口80,详见harbor.yml)
1 | push repository:tag, |
Pull Image from Harbor
Step 1
add the option --insecure-registry
to your client’s Docker daemon. By default, the daemon file is located at /etc/docker/daemon.json
.
1 | { |
Restart Docker Engine.
1 | systemctl restart docker |
Step 2
1 | docker pull hostAddress/library/REPOSITORY:TAG |