Steps to create, test and push a docker image

  1. Download and install Docker Desktop. If on Linux, download Docker Engine - Community.
  2. Create a Docker file with the name Dockerfile or download one.
  • Simple docker file example

      FROM ubuntu:18.04
      RUN apt-get update
      RUN apt install -y python3
      RUN python3 --version
    
  • Official Example

  • Advanced Example

      >notepad Dockerfile
    
  1. Login to docker hub

     >docker login
    
  2. Make changes to docker file and build it

     >docker build --rm -t krishan_apex:latest .
        
     Sending build context to Docker daemon  3.584kB
     **** installs a bunch of packages ***
     **** installs some more packages ***
     Successfully built 4a4cc017fe68
    
  3. See the list of docker images

     > docker images
     REPOSITORY                           TAG                                        IMAGE ID            CREATED             SIZE
     krishan_apex                         latest                                     4a4cc017fe68        2 minutes ago       6.33GB
    
  4. Create a repository in docker hub

  5. Tag your image with <username>/<reponame>:<tag>

     > docker tag krishan_apex krishansubudhi/pytorch_apex:latest
    
  6. Run the container on your machine using the image you just created.

     > docker run -it -d -p 5000:5000  krishansubudhi/pytorch_apex:latest
    
  7. Check all running docker containers

     > docker ps
        
     CONTAINER ID        IMAGE                                COMMAND             CREATED             STATUS              PORTS                                                  NAMES
     55c7cfc80e35        krishansubudhi/pytorch_apex:latest   "/bin/bash"         15 seconds ago      Up 13 seconds       5001/tcp, 8883/tcp, 0.0.0.0:5000->5000/tcp, 8888/tcp   angry_elbakyan
    
  8. Log in to terminal of runing container and run simple linux commands.

     docker attach 55c7cfc80e35
    
  9. Push the image to dockerhub repo to be accessed by everyone. This takes a long time.

    docker push krishansubudhi/pytorch_apex:latest
    

Reference :

IBM tutorial Official documentation What is Docker. RUN vs CMD vs ENTRYPOINT