DEV Community

denOldTimer
denOldTimer

Posted on

Transfer Docker Image from PC to Server

How to transfer Docker Image from your PC to your Server

This article is to help developers transfer docker images from their Pc to their Webserver without going through DockerHub.

Why?

To reduce DockerHub requests!

Example!

In this example, I'll be showing how to transfer from a Windows PC to a Ubuntu Linux Webserver.

Step 1 Open your project in the root directory

ex. cd /Users/sammy/projects/cars

Step 2 Build your image

docker build -t <dockerhubAccountname>/<imageName>:<version> .
ex. docker build -t sammy/cars:1.0 .
Do not forget the dot . for the current file.

Step 3 Save your Image as a compressed file.

docker save -o /Users/sammy/cars.tar sammy/cars:1.0

Step 4 Upload the compressed File to your Webserver.

I use Filezilla and upload the file to the root user directory.
or One can try rsync.
rsync -avz cars.tar sammy@cars.com:/home/sammy/

Step 5 Ssh onto your Webserver

ssh sammy@cars.com + password

Step 6 Load the image into Docker on the Webserver

sudo docker load -i cars.tar

Step 7 Check if the Image is loaded.

sudo docker images

Step 8 Run the image in a container

sudo docker run -d --name sammycars -p 8080:80 sammy/cars:1.0

Step 9 Check if the container is running.

sudo docker container la -a

NOTE !!

If you rinse and repeat first stop the current container and remove it.
sudo docker stop sammycars
sudo docker rm sammycars
Then remove the Image
sudo docker rmi sammy/cars:1.0

Footnote

I hope this was helpful and if already known, a cheatsheet then.

Top comments (0)