Docker File - (02) - Day 34
Table of contents
Dockerfile
Dockerfile is a text file containing various instructions and configurations in the form of commands. Dockerfile helps to build a Docker image.
📝DockerFile Syntax:
| :[taking base image from Docker Hub] |
| :[Set the working directory in the container] |
| :[Copy the current directory contents into the container at /app] |
| [Install any needed packages specified in requirements.txt for building the image] |
| [Make port available to the world outside this container] |
| [Run specified command when the container launches] |
📌Task:
Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)
-Create a project directory on your ec-2 instance and clone the git repo where node.js source code is present
-Write a Docker file in the project directory to build a Docker image for the application
-Docker file created:
Build the image using the Dockerfile and run the container
-While creating the image I received the below message. When I checked the docker status then got to know the docker was installed but the service was inactive. I started the docker service and check the status, it was running.
-Built docker image by running command docker build . -t <tag-name>
-Verified created docker image:
-To create a container from docker Image, run the command :
[docker run -d -p 8001:8001 todo-app]
-To check the running container [
docker ps -a
]Verify that the application is working as expected by accessing it in a web browser
-Try to access aap through ec2 URL:
-Enable Allowed host in
settings.py
file under the todoApp directory:-Deploy the image :
Push the image to a public or private repository (e.g. Docker Hub )
-sign in to docker.hub registry and create a repository
-Login into your docker registry using
docker login
command from the ec2 instance-If you try to push your image without tag name, can face below message:
-Provide tag of the image according to the repository you have created:
-Push your image to the docker hub:
-Able to see the pushed image over the docker hub registry: