0

I'm new to Docker, and I'm trying to deploy a django site with Docker & Gunicorn. The Docker image builds just fine, but I keep getting this error when attempting to run it.

touch: cannot touch '/srv/logs/gunicorn.log': No such file or directory touch: cannot touch '/srv/logs/access.log': No such file or directory Starting Gunicorn. tail: cannot open '/srv/logs/*.log' for reading: No such file or directory

If I had to bet, I would say it's an issue with me not understanding these Docker Volumes

Here are the relevant files:

Dockerfile

FROM ubuntu:18.04

MAINTAINER ozymandias
ENV DOCKYARD_SRC=agency
ENV DOCKHARD_SRVHOME=/srv
ENV DOCKYARD_SRVPROJ=/srv/agency

RUN apt-get update && apt-get -y upgrade
RUN apt-get install -y python3 python3-pip

WORKDIR $DOCKYARD_SRC
RUN mkdir media static logs
VOLUME ["$DOCKYARD_SRVHOME/media/", "$DOCKYARD_SRVHOME/logs/"]
RUN ls

copy $DOCKYARD_SRC $DOCKYARD_SRVPROJ

RUN pip3 install -r $DOCKYARD_SRVPROJ/requirements.txt

EXPOSE 8000

WORKDIR $DOCKYARD_SRVPROJ
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

docker-entrypoint.sh

#!/bin/bash
python3 manage.py migrate
python3 manage.py collectstatic --noinput
ls
touch /srv/logs/gunicorn.log
touch /srv/logs/access.log
tail -n 0 -f /srv/logs/*.log &

echo Starting Gunicorn.
exec gunicorn front.wsgi:application \
    --name agency \
    --bind 0.0.0.0:8000 \
    --workers 3 \
    --log-level=info \
    --log-file=/srv/logs/gunicorn.log \
    --access-logfile==/srv/logs/access.log \
    "$@"

Ozymandias
  • 47
  • 1
  • 6
  • try to use `ARG` instruction instead of `ENV`. You can see the difference between them [here](https://stackoverflow.com/questions/41916386/arg-or-env-which-one-to-use-in-this-case). – Hayk Davtyan Aug 23 '22 at 21:22
  • Reading through this it seems like `/srv/logs` _should_ exist when you launch the container, but its a roundabout path. Can you start the setup sequence with `WORKDIR /srv`, create directories relative to the current directory, and remove all of the environment variable setup? `VOLUME` largely has confusing side effects and I'd just delete the `VOLUME` line, which may or may not make a difference. – David Maze Aug 24 '22 at 12:54
  • I'd also be interested to see what's in `docker run --rm --entrypoint ls your-image /`; I expect to see a `/agency` directory and wouldn't be surprised if there was a `/agency/$DOCKYARD_SRVHOME/logs` directory (with that literal string). If you do I can explain why, but it's not clear in the Dockerfile reference. – David Maze Aug 24 '22 at 12:57
  • I changed the Dockefile to avoid using the ENV variables, and removed the VOLUME[], and still get the same errors. The output of the command `docker run --rm --entrypoint ls ozy/django_one /` is : agency bin boot dev docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var – Ozymandias Aug 25 '22 at 19:13

0 Answers0