Docker – How to easily build and publish an image

docker photo

First we need a Dockerfile which we want to build. Creating a Dockerfile will not be covered in this post. This post details how to build and publish/push an existing Dockerfile.

Photo by maijou2501


  1. First we need to make a build directory:

    mkdir ~/docker-build
    
  2. Then we need to cd into our new directory and get our Dockerfile, for this example I will be using my modified wazuh-kibana-elastalert Dockerfile:

    cd ~/docker-build
    wget https://gitea.trader418.me/trader418/wazuh-docker/raw/branch/master/kibana/Dockerfile
    
  3. Now we build the Docker image. At the same time we are tagging our image, in this example I am tagging with the user/repository “yourUsername”, the image name “yourImageName” and the tag “latest”:

    docker build -t yourUsername/yourImageName:latest .
    
  4. Once this has completed, you should be able to see the newly built image using the following command:

    docker images
    
  5. Now we need to authenticate with the docker repository so we can push our new image:

    docker login docker.io
    

    At this point you should be prompted for your docker hub credentials.

  6. Now we can push your new image to the docker repository:

    docker push yourUsername/yourImageName:latest
    

You May Also Like

Leave a Reply

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