Skip to content

Instantly share code, notes, and snippets.

@tumainimosha
Created May 8, 2024 10:59
Show Gist options
  • Save tumainimosha/8846b4e9a695c1d8ebf8ee699e857143 to your computer and use it in GitHub Desktop.
Save tumainimosha/8846b4e9a695c1d8ebf8ee699e857143 to your computer and use it in GitHub Desktop.
Docker config files for running python project on server using docker
# App port. Specifies port for appserver
PORT=8000

Docker config files for running python project on server using docker

1. To build the app container

docker-compose build

2. To start the container

docker-compose up -d

Step 1 & 2 combined: To rebbuild and start

You can both build and start the up. This will also rebuild if the container is already existing, and you have made changes to the app

docker-compose up -d --build
version: "3"
services:
### Pythoon App Container ###########################
web:
build:
context: ./
restart: unless-stopped
command: "python manage.py runserver 0.0.0.0:8000"
ports:
- ${PORT}:8000
volumes:
- .:/pos
networks:
- frontend
### Networks Setup ############################################
networks:
frontend:
driver: "bridge"
# Python support can be specified down to the minor or micro version
# (e.g. 3.6 or 3.6.3).
# OS Support also exists for jessie & stretch (slim and full).
# See https://hub.docker.com/r/library/python/ for all supported Python
# tags from Docker Hub.
FROM python:3.11-bullseye
# Here working directory is "/pos" because my django project is in "pos" folder.
# Change this to match your project folder name
WORKDIR /pos
COPY requirements.txt /pos/
RUN apt-get -y install libpq-dev \
&& apt-get clean
# Using pip:
RUN pip install -r requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment