Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Push and Pull a Docker Image with Docker Hub

Log in to Docker Hub, tag an image, push it and pull it on another machine.

VPS and Cloud Servers2 min read6 screenshots

Push and pull

  • Push uploads an image to a registry, here Docker Hub.
  • Pull downloads an image from it.

Docker Hub is the official public registry. A free account gives you public repositories and a limited number of private ones.

Step 1: Install Docker

Install Docker on your machine. On Ubuntu: sudo apt install docker.io.

Step 2: Create an account and log in

Create a free account on hub.docker.com.

The Docker Hub account page

Log in from the terminal:

docker login
Logging in to Docker Hub from the terminal

Enter your username and password (or an access token, which is safer and can be created under Account Settings > Security).

Step 3: Tag the image

List your images and find the image ID:

docker images
Listing the Docker images

Tag it with your Docker Hub username and a repository name:

docker tag <image_id> <username>/<repository_name>:<tag>

Example:

sudo docker tag d2c94e258dcb user864/myhello:latest
Tagging the image

You can also tag by name instead of ID, for example docker tag myhello user864/myhello:latest.

Step 4: Push the image

docker push <username>/<repository_name>:<tag>

Example:

sudo docker push user864/myhello:latest
Pushing the image to Docker Hub

The image now appears in your repository on Docker Hub.

Step 5: Pull the image

On any machine with Docker:

docker pull <username>/<repository_name>:<tag>

Example:

docker pull user864/myhello:latest
Pulling the image from Docker Hub

Run it:

docker run user864/myhello:latest

Security considerations

  • Do not put passwords, keys or secrets in an image. Anyone who pulls a public image can read them.
  • Use access tokens instead of your password, and log out on shared machines with docker logout.
  • Use private repositories for private code.
  • Scan images for known problems and use trusted base images.
  • Pin tags like 1.2.3 instead of latest for production.

Quick recap

  • docker login, docker tag, docker push, docker pull.