0%

docker migration

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

commit command

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
2
# create image from container
docker container commit c16378f943fe rhel-httpd:latest

Step 2

tag the image with the host name or IP address, and the port of the registry:

1
2
3
4
# re-tag repository:tag info about image
docker image tag rhel-httpd:latest registry-host:5000/myadmin/rhel-httpd:latest
or
docker tag 0e5574283393 registry-host:5000/myadmin/rhel-httpd:latest

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
2
3
4
# push repository:tag,
docker image push registry-host:5000/myadmin/rhel-httpd:latest
or
docker push registry-host:5000/myname/myimage

Pull Image from Harbor

Connecting to Harbor via HTTP

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
2
3
{
"insecure-registries" : ["ip:port", "0.0.0.0"] #如果port为80,则可省略
}

Restart Docker Engine.

1
systemctl restart docker

Step 2

1
docker pull hostAddress/library/REPOSITORY:TAG