git clone https://github.com/atulkamble/docker-python-app.git
cd docker-python-app
-
Ensure Docker is installed on your system: Install Docker if it’s not already installed:
sudo yum install docker -y
-
Install Git: If Git is not installed, install it:
sudo yum install git -y
-
Install Python: If Python is not installed, install it:
sudo yum install python -y
-
Clone the Docker Python Project Repository:
git clone https://github.com/atulkamble/dockerpythonproject.git cd dockerpythonproject
-
Setup Docker: Start the Docker service:
sudo systemctl start docker
Enable Docker to start on boot:
bash sudo systemctl enable docker
Verify Docker installation:
bash docker --version
-
Clone the Test DevOps Project Repository:
git clone https://github.com/atulkamble/testdevopsproject.git cd testdevopsproject/
-
Configure Git: Set up your Git user details:
git config --global user.name "atulkamble" git config --global user.email "atul_kamble@hotmail.com"
-
Create and Test Python Script: Create a Python script file:
touch sum.py sudo nano sum.py
Add your Python code to sum.py
and test it:
bash python3 sum.py
- Create Dockerfile:
Create a Dockerfile:
touch Dockerfile sudo nano Dockerfile
Add the following content to your Dockerfile: ```dockerfile # Use the official Python image from the Docker Hub FROM python:3.8-slim
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run sum.py when the container launches
CMD ["python", "sum.py"]
```
- Build and Push Docker Image:
Log in to Docker Hub:
sudo docker login
Build your Docker image:
bash sudo docker build -t atuljkamble/pythonproject .
Verify the Docker image is built:
bash sudo docker images
Push the Docker image to Docker Hub:
bash sudo docker push atuljkamble/pythonproject
- Run Docker Container:
Run your Docker container:
sudo docker run atuljkamble/pythonproject
List all Docker containers to verify it is running:
bash sudo docker ps -a
By following these steps, you will have successfully Dockerized your Python application, built a Docker image, and run it as a container.