Acutally, this is example of my Dockerfile
and docker-compose.yml
.
I worked on mac OS.
I would like to run my django app inside docker container, but I didn't want to use container with postgres db inside docker. I have already installed and running postgres instance with all data I need.
So django is in container, postgres is out.
- My
Dockerfile
:
FROM python:3.8-alpine
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
Nothing special here. Just create app, running requirements for environment.
- My
docker-compose.yml
:
version: "3.8"
services:
web:
build: .
command: >
sh -c "python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
volumes:
- .:/code
ports:
- "8008:8000"
environment:
- DB_NAME=YOUR_DB_NAME_HERE
- DB_USER=YOUR_DB_USER_HERE
- DB_PASSWORD=YOUR_DB_PASSWORD_HERE
- DB_HOST=docker.for.mac.localhost
For me all magic was in line with docker.for.mac.localhost
.