๐ณ๐ ๏ธDay 17: Docker Project for DevOps Engineers
๐ณ๐ฆ What is Dockerfile??
A Dockerfile is a text file that contains a set of instructions for building a Docker image.
It selects the base image, sets up the environment, installs dependencies, and explains how the application should run within a Docker container.
๐๐ณCreating a Docker Image for a Simple Python Web Application:
๐พStep 1: Create a Dockerfile for a simple web application (e.g. a Python app)
# Get a base image with python 3.7
FROM python:3.8-slim
# Set the workding directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . .
# Install all the required dependencies specified in requirements.txt
RUN pip install -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Run the python app
CMD ["python","app.py"]
๐พStep 2: Build the image using the Dockerfile, and execute the following command in the same directory as the Dockerfile
docker build . -t python:latest
๐พStep 3: Run the container
docker run -d -p 80:80 python:latest
๐พStep 4: Verify that the application works as expected by accessing it in a web browser at http://localhost:80
๐พStep 5: Push the image to a public or private repository (e.g. Docker Hub)
docker push <image:tag-name>
Note:
- Make sure you're logged into Docker Hub before using the docker push command.
๐ Feel free to use these commands to manage your Docker images! ๐ณ
Happy Coding :) ๐โก
โ Feel free to reach out if you have any questions. I'm delighted to help! ๐
๐ค Let's Connect..!
๐ LinkedIn
๐ Twitter
๐ GitHub
โ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธโ๏ธ
Subscribe to my newsletter
Read articles from sushil pawar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
sushil pawar
sushil pawar
๐ฑ Aspiring Fresher with Big Dreams! ๐ Hey there! ๐ I'm Sushil Pawar, a fresh face eager to embark on a journey of greatness. ๐ Committed to learning, sharing thoughts, and growing together. ๐๐ฌ