- Priya
- January 21, 2023
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.
- Install docker on ubuntu 20.04 so click on link https://www.hackerxone.com/blog/how-install-docker-ubuntu-2004-lts for how to install docker.
- Once docker is installed.
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 ./start.sh /
RUN chmod 777 /start.sh
RUN /start.sh
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
[supervisord]
nodaemon=true
[program:apache2]
command=/usr/sbin/apache2ctl -D FOREGROUND
autorestart=true
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
localhost:80
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
- Install aws-cli & configure aws on ubuntu so click on link https://www.hackerxone.com/blog/how-install-configure-aws-cli-ubuntu-1804
- Create a repository & Login to ECR so click on link https://www.hackerxone.com/blog/how-create-configure-elastic-container-registry-amazon-web-serviceaws for how to create repository on 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