Flow-2: Create a new Docker Image, Run as Container and Push to Docker Hub
Pre-requisite Steps
- Create your Docker hub account.
- https://hub.docker.com/
- Important Note: In the below listed commands wherever you see stacksimplify you can replace with your docker hub account id.
Step-1: Run the base Nginx container
- Access the URL http://localhost
docker run --name mynginxdefault -p 80:80 -d nginx
docker ps
docker stop mynginxdefault
Step-2: Create Dockerfile and copy our customized index.html
- Dockerfile
FROM nginx
COPY index.html /usr/share/nginx/html
- *index.html
<!DOCTYPE html>
<html>
<body style="background-color:lightgoldenrodyellow;">
<h1>Welcome to Stack Simplify</h1>
<p>Docker for Beginners Demo</p>
<p>Application Version: V1</p>
</body>
</html>
- Reference Link: https://github.com/stacksimplify/docker-fundamentals/tree/master/04-Build-new-Docker-Image-and-Run-and-Push-to-DockerHub/Nginx-DockerFiles
Step-3: Build Docker Image & run it
docker build -t stacksimplify/mynginx_image1:v1 .
docker run --name mynginx1 -p 80:80 -d stacksimplify/mynginx_image1:v1
Replace your docker hub account Id
docker build -t <your-docker-hub-id>/mynginx_image1:v1 .
docker run --name mynginx1 -p 80:80 -d <your-docker-hub-id>/mynginx_image1:v1
AWS EKS - Elastic Kubernetes Service - Masterclass
Step-4: Tag & push the Docker image to docker hub
docker images
docker tag stacksimplify/mynginx_image1:v1 stacksimplify/mynginx_image1:v1-release
docker push stacksimplify/mynginx_image1:v1-release
Replace your docker hub account Id
docker tag <your-docker-hub-id>/mynginx_image1:v1 <your-docker-hub-id>/mynginx_image1:v1-release
docker push <your-docker-hub-id>/mynginx_image1:v1-release
Step-5: Verify the same on docker hub
- Login to docker hub and verify the image we have pushed
- Url: https://hub.docker.com/repositories