Logo

Armand.nz

Home / About / Linkedin / Github

Pushing and Pulling to and from Docker Hub

#docker |

Pull and run an image from Docker Hub

Docker Hub is the place where open Docker images are stored. When we ran our first image by typing

docer run --rm -p 80:80 hubusername/app_name  

Running a docker run will use a docker image available locally and will try to pull the image if not available . If you just want to pull the image but not run it, you can run:

docker pull hubusername/app_name  

Push an image to Docker Hub

We will use https://hub.docker.com/ for our example:

  1. Log in on https://hub.docker.com/
  2. If you want to create a private Repository: Choose a name (e.g. my_app) and a description for your repository and click Create.
    See: Creating repositories. You can skip this step for public repos

  3. Log into the Docker Hub from the command line

     docker login --username=yourhubusername  
    
  4. Check the image ID with the command:

     docker images  
    

    and what you will see will be similar to

     REPOSITORY TAG IMAGE ID CREATED SIZE  
     my_app latest 023ab91c6291 3 minutes ago 1.235 GB  
    
  5. Now tag your image with your docker hub username.

    Note: If you are using Docker hub you dont need to provide the docker registry URI just the docker hub username

    Its a good idea to tag the container image with something that is descriptive of the build, i.e. Semantic Versioning or build name. A best pratice is to streamline tagging in your CICD workflow with your the build hash.

    Since we are doing a manual push we can tag it with a version number.

    The number must match the IMAGE ID and :mytag is the tag:

     # docker tag [IMAGE ID] yourhubusername/my_app:mytag  
            
     docker tag 023ab91c6291 armsultan/my_app:v0.3.0  
    
  6. Push your image to the repository you created

     docker push yourhubusername/my_app  
    

Saving and loading images

It is possible to save a Docker image after you have it available on your local machine using the docker save command.
This is useful if you want to share the image “offline” with no dependency on access to the online docker repository

To save a local copy of the my_app for portablity, run:

docker save my_app > my_app.tar  

And to load it, use the docker load command:

docker load --input my\_app.tar  
comments powered byDisqus

Copyright © Armand