Docker rookie here, trying to setup a simple Django project using Compose. I've had success with this in the past, but I'm trying a different setup this time, which I can't figure out why it doesn't work.
I have the following docker-compose.yml file:
data:
image: postgres:9.4
volumes:
- /var/lib/postgresql
command: /bin/true
db:
image: postgres:9.4
restart: always
expose:
- "5432"
volumes_from:
- data
app:
build: .
restart: always
env_file: .env
expose:
- "8000"
links:
- db:db
volumes:
- .static:/static_files
web:
build: docker/web
restart: always
ports:
- "80:80"
links:
- app:app
volumes_from:
- app
My /Dockerfile is:
FROM python:3.5
ENV PYTHONUNBUFFERED 1
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt
RUN SECRET_KEY=tmpkey python manage.py collectstatic --noinput
CMD gunicorn mysite.wsgi:application -b 0.0.0.0:8000
My /docker/web/Dockerfile is:
FROM nginx:1.9
RUN rm /etc/nginx/conf.d/default.conf
ADD default.conf /etc/nginx/conf.d/
And my /docker/web/default.conf file is:
server {
listen 80 default_server;
location /static/ {
autoindex on;
alias /static_files/;
}
location / {
proxy_pass http://app:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
The output from docker shows the static files installing into /static_files, but nginx returns 404 for all the files under /static. If I look in my .static folder (in root of project), the directory is empty (aside from a .gitkeep file I have in there). If I run docker-compose app run ls -la /static_files
, the directory is empty, but docker-compose app run ls -la /app/.static
has the .gitkeep file. Clearly I'm misunderstanding something with Docker and Compose. Any thoughts on what I'm doing wrong? My understanding is that the RUN SECRET_KEY=tmpkey python manage.py collectstatic --noinput
should be writing files to my local .static folder and that nginx should see these files; neither is happening.
Software versions: docker-compose version 1.7.0, build 0d7bf73 and Docker version 1.11.0, build 4dc5990 on OS X, with docker-machine connected to cloud instance.