How to Create Docker Image & Pushed to Docker Hub or Amazon Elastic Registry

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.

Docker hub is the repository of container images. We can easily create own docker hub account & we can upload/push or pull docker images any time any where with the help on internet.


Create Docker-image

Create a folder where all docker file are placed

mkdir  project

Create a file,provide a name dockerfile.

touch dockerfile

Open dockerfile using vim editor

vim dockerfile

Under dockerfile,write the code in docker supported format.For example

FROM ubuntu:18.04
Run apt update -y

If we needs to run a scriptfile with dockerfile.Add these line on dockerfie

COPY ./ /
RUN chmod 777 /

If we needs to run multiple services with dockerfile.Install supervisor

RUN apt-get update -y --fix-missing && apt-get install -y  supervisor

Create a supervisord.conf file

vim supervisord.conf

We can run multiple services with dockerfile. For example

command=/usr/sbin/apache2ctl -D FOREGROUND

At dockerfile mention a code to copy the supervisord.conf file

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

Finally Dockerfile is ready for creating image. Run the following command:

docker build -t image_name  . 

List the dockerfiile

docker images ls

Create a container

docker run -d -v -p 80:80 image_name 

Login to container

docker exec -it conatiner-id  sh or /bin/bash

Now test docker-image using curl command on the port 80

curl localhost:80

We can also check docker-image on web browser


Push Docker-image to Docker-Hub

Login to Dockerhub

docker login

Then Provide username & password of dockerhub.

Provide a tag on docker-image

docker tag image-name dockerhub-ownername/image-name:version

Push docker-image to docker-hub

docker push dockerhub-ownername/image-name:version

Push Docker-image to Amazon Elastic Registry

Provide a tag on docker-image

docker tag image-name ECR-uri/repo-name:version

Push docker-image to docker-hub

docker push ECR-uri/repo-name:version


Leave a Reply