Saving a Docker Image and Using It On A Different Server

Problem Scenario
Sometimes the "docker save" command does not work as you would expect.  You run the command on a Docker host, but it does not work.  You might even try the -o flag or the --output=/tmp/destinationFileName.tar option.  But the response may be an surprising error "Cowardly refusing to save to a terminal. Use the -o flag or redirect."  You want to copy a Docker image from one machine to another computer but problems get in your way.  How do you solve this problem so you can transfer a flat file to another server and use the Docker image?  In other words, how do you do the most basic task with Docker, how do you bring a copy of a Docker container to another machine (another virtual server, a different Docker host)?

You must have Docker installed.  If you need help installing Docker, see this posting.

The redirect in the error is the right clue.  This solution assumes you have Docker installed on the different server. 

From the Docker host, use these three steps to copy a Docker container and place the container on another machine (server or host).

Step #1:  This command should work:
docker save repositoryName:versionName > /tmp/destinationFileName.tar

Alternatively, you could try this command:
docker save ImageName > /tmp/imagename.tar
# You could find the ImageName by running "docker ps -a" and looking at the results.

Step #2:  The above command will save the image as a regularly accessible flat file with the name destinationFileName.tar.  To use it on the destination Docker host, transfer it to that server.  Use scp or sftp to do the file transfer to a different server. 

Step #3:  Then use this command (assuming the location of the file on the destination server is /tmp/) on the different host:  
​docker load < /tmp/destinationFileName.tar

By the way, there are numerous books on Docker.

Leave a comment

Your email address will not be published. Required fields are marked *