Reputation: 1150
I am trying to dockerize django using gunicorn and nginx into a docker image. from this tutorial
Running docker-compose up --detach --build
Everything builds successfully. But gunicorn is not starting. Error log says:
bash: /home/soccer/venv/bin/gunicorn: /Users/Umar/PycharmProjects/soccer/venv/bin/python: bad interpreter: No such file or directory
How can I fix this?
Dockerfile:
# pull official base image
FROM python:3.7
# accept arguments
ARG PIP_REQUIREMENTS=production.txt
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install --upgrade pip setuptools
# create user for the Django project
RUN useradd -ms /bin/bash soccer
# set current user
USER soccer
# set work directory
WORKDIR /home/soccer
# create and activate virtual environment
RUN python3 -m venv venv
# copy and install pip requirements
COPY --chown=soccer ./requirements /home/soccer/requirements/
RUN pip3 install -r /home/soccer/requirements/${PIP_REQUIREMENTS}
# copy Django project files
COPY --chown=soccer . /home/soccer/
docker-compose.yml:
version: "3.8"
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
- static_volume:/home/soccer/static
- media_volume:/home/soccer/media
depends_on:
- gunicorn
gunicorn:
build:
context: .
args:
PIP_REQUIREMENTS: "${PIP_REQUIREMENTS}"
command: bash -c "/home/soccer/venv/bin/gunicorn --workers 3 --bind 0.0.0.0:8000 soccer.wsgi:application"
depends_on:
- db
volumes:
- static_volume:/home/soccer/static
- media_volume:/home/soccer/media
expose:
- "8000"
environment:
DJANGO_SETTINGS_MODULE: "${DJANGO_SETTINGS_MODULE}"
DJANGO_SECRET_KEY: "${DJANGO_SECRET_KEY}"
DATABASE_NAME: "${DATABASE_NAME}"
DATABASE_USER: "${DATABASE_USER}"
DATABASE_PASSWORD: "${DATABASE_PASSWORD}"
db:
image: postgres:latest
restart: always
environment:
POSTGRES_DB: "${DATABASE_NAME}"
POSTGRES_USER: "${DATABASE_USER}"
POSTGRES_PASSWORD: "${DATABASE_PASSWORD}"
ports:
- 5432
volumes:
- postgres_data:/var/lib/postgresql/data/
volumes:
postgres_data:
static_volume:
media_volume:
Upvotes: 0
Views: 313
Reputation: 1150
I found the issue. I was overwriting venv. The solution is to add virtual env to .dockerinfo file.
Upvotes: 1