Export and Import a Docker Image Between Nodes

Export and Import a Docker Image Between Nodes

Get Social!

docker-logoOne of the driving forces behind Docker is to create a consistent environment across all Docker enabled machines and to create portable templates, or images, which can be ran on any Docker enabled server.

It would, therefore, make perfect sense that Docker have made it very easy for us to export a running container and re-import it on another Docker server.

Lets assume, for this example, that you have a running container that you would like to move to another host. The summary of the process is to save the container to an image, save it to a tar file, move it to your new host and load the image into the new docker server.

Find the ID of the container that you would like to move.

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
f4b0d7285fec        ubuntu:14.04        /bin/bash           38 minutes ago      Exit 0                                  hungry_thompson
8ae64c0faa34        ubuntu:14.04        /bin/bash           41 minutes ago      Exit 0                                  jovial_hawking
3a09b2588478        ubuntu:14.04        /bin/bash           45 minutes ago      Exit 0                                  kickass_lovelace

I’m going to use the above 3a09b2588478 ID for this example.

Commit your changes and save the container to an image called mynewimage.

$ docker commit 3a09b2588478 mynewimage
4d2eab1c0b9a13c83abd72b38e5d4b4315de3c9967165f78a7b817ca99bf191e

Save the mynewimage image to a tar file. I will use the /tmp/ directory to save the image but you could easily use a NFS share to make it easier to move the completed tar file.

$ docker save mynewimage > /tmp/mynewimage.tar

Copy the mynewimage.tar file to your new Docker instance using whatever method works in your environment, for example FTP, SCP, etc.

Run the docker load command on your new Docker instance and specify the location of the image tar file.

$ docker load < /tmp/mynewimage.tar

Finally, run the docker images command to check that the image is now available.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
mynewimage          latest              4d2eab1c0b9a        5 minutes ago       278.1 MB
ubuntu              14.04               ad892dd21d60        11 days ago         275.5 MB
<none>              <none>              6b0a59aa7c48        11 days ago         169.4 MB
<none>              <none>              6cfa4d1f33fb        7 weeks ago         0 B

Copy MySQL Database to Another Server

Category : How-to

Get Social!

mysql-logoThe easiest way to do a one off move of a MySQL database from one server to another is to use the mysqldump utility. This utility will dump the entire database and it’s content to a file and which can then be imported it into the target database.

Before running the export, you should make sure you have enough free space to hold the database. The bigger the database, the more free space you will need for the SQL dump.

Run the below command to export your database from the source server. Replace [EXPORT_DATABASE] with the name of the database to export.

mysqldump -uroot -p [EXPORT_DATABASE] -r /location/to/export/to.sql

If required, move the SQL dump file to the target server. On the target server, run the below command to connect, create the database and import the data. Change [USERNAME] to the user you would like to connect as and [DATABASE_NAME] to the name of the databse where the dump file will be imported. The [DATABASE_NAME] will most likely be the same as on the source database however you are able to change it if required.

mysql -p -u [USERNAME] [DATABASE_NAME] < /location/to/export/to.sql

Visit our advertisers

Quick Poll

Which type of virtualisation do you use?
  • Add your answer

Visit our advertisers