Day 17 Task: Docker Project for DevOps Engineers.
"Crafting Container Environments: A Guide to Dockerfile Creation"
Table of contents
Dockerfile
Docker is a tool that makes it easy to run applications in containers. Containers are like small packages that hold everything an application needs to run. To create these containers, developers use something called a Dockerfile.
A Dockerfile is like a set of instructions for making a container. It tells Docker what base image to use, what commands to run, and what files to include. For example, if you were making a container for a website, the Dockerfile might tell Docker to use an official web server image, copy the files for your website into the container, and start the web server when the container starts.
The Dockerfile provides a set of instructions that Docker follows to build an image for your application. Here are the commands commonly used in a Dockerfile:
FROM: Specifies the base image to build upon.
Example:
FROM python:3.8
WORKDIR: Sets the working directory inside the container where the application will be placed.
Example:
WORKDIR /usr/src/app
COPY: Copies files or directories from your local machine to the container.
Example:
COPY requirements.txt ./
RUN: Executes a command during the image build process. Commonly used for package installations.
Example:
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE: Exposes a port that the container will listen on.
Example:
EXPOSE 5000
CMD: Specifies the command to run when the container starts.
Example:
CMD [ "python", "
app.py
" ]
ENTRYPOINT: Similar to CMD, but it's not overridden by command-line arguments.
ENV: Sets environment variables inside the container.
VOLUME: Creates a mount point for a volume.
USER: Sets the user that the container process runs as.
WORKDIR: Sets the working directory within the container.
๐ถ Task-1 :
- Create a Dockerfile for a simple web application (e.g. a Node.js or Python app)
FROM node:12.2.0-alpine
WORKDIR app
COPY . .
RUN npm install
RUN npm run test
EXPOSE 8000
CMD ["node","app.js"]
- Build the image using the Dockerfile and run the container
docker build . -t node-app
docker run -d -p 8000:8000 node-app
- Verify that the application is working as expected by accessing it in a web browser
docker tag node-app nileshsahare/nilesh07/todo-app:node-app
docker login
Push the image to a public or private repository
(e.g. Docker Hub )
docker push nileshsahare/nilesh07/todo-app:node-app
If you find my blog valuable, I invite you to like, share, and join the discussion. Your feedback is immensely cherished as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together! ๐ #devops #90daysofdevop #git&github #docker