0

I've had issues with Dockerfile due to random files like 'chunk' in the static folder. I resolved this with a fresh clone of my repository as the chunk files disappeared, see here.

So it works perfectly fine when I just run using the image alone using docker run --rm -d mellon:latest.

Here is the Dockerfile:

FROM (MY FRIENDS ACCOUNT)/django-npm:latest

RUN mkdir usr/src/mprova

WORKDIR /usr/src/mprova

COPY frontend ./frontend
COPY backend ./backend

WORKDIR /usr/src/mprova/frontend

RUN npm install
RUN npm run build

WORKDIR /usr/src/mprova/backend

ENV DJANGO_PRODUCTION=True
RUN pip3 install -r requirements.txt

EXPOSE 8000

CMD python3 manage.py collectstatic && \
    python3 manage.py makemigrations && \
    python3 manage.py migrate && \
    gunicorn mellon.wsgi --bind 0.0.0.0:8000

Now (as per advised by people online) I am trying to separate the app from the database so I have written a docker-compose.yml file.

version: '3'

services:
  db:
    image: postgres
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=(adminname)
      - POSTGRES_PASSWORD=(adminpassword)
      - CLOUDINARY_URL=(cloudinarykey)
  web:
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - ./backend:/usr/src/mprova/backend
    ports:
      - "8000:8000"
    depends_on:
      - db

(Also annoyingly - I have to go into bash and run python3 manage.py makemigrations and python3 manage.py migrate every time even though it's already in the Dockerfile???)

Now when I run the following commands: docker-compose build docker-compose up

It does all the steps, yet in the browser I see the same issue that I did in my previous post. Here is a screenshot:

enter image description here

And here is the console (Google Chrome):

enter image description here

Just to be clear, I did not write any of the files which are shown above in the screenshot, they're all generated and I don't know when or how. Upon doing a clean clone and running the Dockerfile (not docker-compose.yml), it is completely fine. Yet when I use docker-compose.yml I run into this error.

I've tried multiple fresh clones of the repo yet the commands to run the docker-compose.yml are definitely generating these static files somehow. What am I doing incorrectly?

John Snow
  • 1,415
  • 1
  • 20
  • 40
user745587
  • 81
  • 8
  • 3
    The `docker-compose.yml` `command:` overrides the `CMD` in the Dockerfile. You can just delete that line to use the default command from the image. Similarly, the `volumes:` hide the work your Dockerfile does in the `backend` directory and replace it with the (possibly extremely different) content from your host, so deleting this is also generally a good practice. – David Maze Aug 01 '20 at 15:46
  • @DavidMaze works perfectly! thank you! – user745587 Aug 01 '20 at 16:07

0 Answers0