🐬Docker
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 Docker file.
🗃️Docker file
A Docker file 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 Docker file 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.
📃Task
1: Create a Dockerfile for a simple web application.
# Use the official Python image as a base image
FROM python:3.9-slim
# Set the working directory inside the container
WORKDIR /app
# Copy the Python quiz app files into the container
COPY . /app
# Install Flask
RUN pip install Flask
# Expose port 5000 for web traffic
EXPOSE 5000
# Run the Flask app when the container starts
CMD ["python", "app.py"]
2: Build the Image and Run the Container
docker build -t my-python-app . #command for build the Docker Image
docker run -p 5000:5000 my-python-app #Run the Docker Container
3: Verify that application is working by accessing it in a web browser at http://localhost:5000
.
4: Push the image to a public or private repository (e.g. Docker Hub )
docker login #Login your Docker Hub
docker tag my-python-app username/my-python-app #Tag your image &
#Replace username with your Docker Hub username.
docker push username/my-python-app #Push the image to Docker Hub
#After pushing the image, it should be available in your Docker Hub repository.
Hope you find it helpful.
😊 Happy learning!