0

I what to dockerize my django app, i create my Dockerfile :

FROM python:3.6-alpine
RUN apk add --no-cache linux-headers libffi-dev jpeg-dev zlib-dev
RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
RUN mkdir /DEV
WORKDIR /DEV
COPY ./requirements.txt .

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1

COPY . .

at this point i create my docker-compose.yml:

version: '3'

networks:
  mynetwork:
    driver: bridge

services:

  db:
    image: postgres
    restart: always
    ports:
      - "5432:5432"
    networks:
      - mynetwork
    environment:
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypass
      POSTGRES_DB: mydb
    volumes:
      - ./data:/var/lib/postgresql/data

  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    networks:
      - mynetwork

    volumes:
      - .:/DEV

    ports:
      - "8000:8000"

    depends_on:
      - db

then i create a .dockerignore file:

# Ignore
.DS_Store
.idea
.venv2
__pycache__
!manage.py
*.py[cod]
*$py.class
*.so
.Python
*.log
docker-compose.yml
Dockerfile
geckodriver.log
golog.py
golog.pyc
log.html
media
out
output.xml
report.html
startup.sh
templates
testlibs
.dockerignore

well, at this point i run:

docker-compose build --no-cache

at the end image was build correctly, but when i run:

docker-compose up

system return this error:

web_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory core_web_1 exited with code 2

Someone can help me about the issue?

so many thanks in advance

0

1 Answer 1

1

Try making your Dockerfile more explicit with the locations and then change your docker-compose as well:

FROM python:3.6-alpine
RUN apk add --no-cache linux-headers libffi-dev jpeg-dev zlib-dev
RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
RUN mkdir /DEV
WORKDIR /DEV
COPY ./requirements.txt /DEV/

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1

COPY . /DEV/
web:
   build: .
   command: python /DEV/manage.py runserver 0.0.0.0:8000
   networks:
       - mynetwork
Sign up to request clarification or add additional context in comments.

2 Comments

python: can't open file '/DEV/manage.py': [Errno 2] No such file or directory core_web_1 exited with code 2
@ManuelSanti Bummer. At this point you need to go ahead and make a container from your image/Dockerfile, attach to it, and navigate to your /DEV folder and see if it contains the manage.py file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.