fir3net
PPS-Firenetbanner-780.5x190-30-03-17

The Essential Guide To Moving Docker Containers

Contents[Hide]

Docker provides various commands/methods for moving containers. Within this article we will look at each of the commands, along with examples needed to move your Docker containers between your hosts and repositories.

Repo to Repo

Lets look at how we get an image from a repository and how we get our local image up to a remote repository.

Pull

The docker pull command is used to  pull an image from a repository.

$ docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
Digest: sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912
Status: Image is up to date for busybox:latest

Tip Docker will pull from docker.io by default. To pull from another repo add the hostname of your registry to the docker pull command, i.e docker pull registry.fir3net.com/busybox [1]

Push

To move images from repository to repository docker push is used. Below shows the steps in involved in pushing an image to a repository,

  1. Authenticate - If required by the repository, authentication is performed with the docker login command.
  2. Tag - Next the repository and a tag is supplied to the docker tag command.
  3. Push - Finally docker push is used to push the image to the repository.

Here is an example,

// LOGIN
$ docker login https://registry.fir3net.com Username: felix001 Password: Login Succeeded

// TAG
$ docker tag busybox registry.fir3net.com/busybox-v0.0.1
// PUSH
$ docker push registry.fir3net.com/busybox-v0.0.1 The push refers to a repository [registry.fir3net.com/busybox-v0.0.1] (len: 1) Sending image list Pushing repository registry.fir3net.com/busybox-v0.0.1 (1 tags) d3a1f33e8a5a: Image successfully pushed c22013c84729: Image successfully pushed d74508fb6632: Image successfully pushed 91e54dfb1179: Image successfully pushed Pushing tag for rev [91e54dfb1179] on {https://registry.fir3net.com/v1/repositories/busybox-v0.0.1/tags/latest}

Host to Host

With host to host, we can take a local image or container and then load (or import) it to another docker environment.

Export vs Save

Ok, so lets look at the docker export and docker save commands,

docker export saves the running or paused instance [2] of a CONTAINER to a TAR-file.
docker save saves an IMAGE to a TAR-file.

Below is an example of both,

Export

$ docker ps
CONTAINER ID        IMAGE               COMMAND 
5e8f397be6fa        busybox             "sh"   

$ docker export 5e8f397be6fa -o busybox-container.tar

Save

$ docker images
REPOSITORY                            TAG                 IMAGE ID
busybox                               latest              e02e811dd08f

$ docker save -o busybox-image.tar busybox

Import vs Load

Finally the commands docker import and docker load are used inline with the TAR-file previous created. So

docker import is used to import a TAR-file (i.e CONTAINER) created by a docker export
docker load is used to load a TAR-file (i.e IMAGE) created by a docker save

// SAVE
$ docker import busybox-container.tar
sha256:94f13e1b4a26cd15a6c6d33da835e7319491a9c1dbeca16583750f7b96235403

// LOAD
$ docker load --input busybox-image.tar
Loaded image: busybox:latest

ReferenceS

[1] http://stackoverflow.com/questions/33054369/how-to-change-the-default-docker-registry-from-docker-io-to-my-private-registry
[2] https://blog.giantswarm.io/moving-docker-container-images-around/

Tags: Docker, Containers

About the Author

RDonato

R Donato

Ricky Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Ricky on Twitter @f3lix001