100-Days-Of-DevOps-Challenge-KodeKloud

Docker Python App

A python app needed to be Dockerized, and then it needs to be deployed on App Server 3. We have already copied a requirements.txt file (having the app dependencies) under /python_app/src/ directory on App Server 3. Further complete this task as per details mentioned below:

Steps

  1. Login into App server and move into directory

     sudo -i
     cd /pythona_app
    
  2. Create Docker file and copy paste the contents:

     sudo vi Dockerfile
    
    
     FROM python:3.9.23-slim
    
     WORKDIR /app
    
     COPY ./src/* /app/
    
     RUN pip install -r requirements.txt
    
     EXPOSE 6300
    
     CMD ["python", "server.py"]
    
  3. Build Docker Image

     docker build -t nautilus/python-app .
    
  4. Run the container

     docker run -d --name pythonapp_nautilus -p 8096:6300 nautilus/python-app
    
  5. Verify

     docker ps
     curl http://localhost:8096
    

Good to Know?

Python Application Containerization

Python Docker Images

Dockerfile Best Practices

Application Deployment