Reputation: 5144
I have two docker-compose services nginx
and django
, and in my command
shell script I perform a gulp task which builds my static files. After the build process is complete, I want to perform a copy command to copy those files to the nginx container, but I'm not sure what command to use.
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile
user: django
depends_on:
- postgres
- redis
command: /gunicorn.sh
env_file: .env
nginx:
build: ./compose/nginx
depends_on:
- django
ports:
- "0.0.0.0:80:80"
#!/bin/sh
gulp build
python manage.py migrate
/usr/local/bin/gunicorn config.wsgi -w 4 -b 0.0.0.0:5000 --chdir=/app
I'm guessing I could use scp within gunicorn.sh
, but i'm not sure how I would reference the nginx
service's IP address.
Upvotes: 2
Views: 3139
Reputation: 469
Just share volumes between containers, there is no need to actually copy the files.
There are multiple ways to define the volumes, but I suppose you don't want these files to be on your host file system.
Try something like the following:
volumes:
- static:
django:
build:
context: .
dockerfile: ./compose/django/Dockerfile
user: django
depends_on:
- postgres
- redis
command: /gunicorn.sh
volumes:
- static:/path/to/your/static/files
env_file: .env
nginx:
build: ./compose/nginx
depends_on:
- django
volumes:
- static:/some/dir/to/serve/files/from/
ports:
- "0.0.0.0:80:80"
And then configure nginx to serve your static files from /some/dir/to/serve/files/from/
.
Upvotes: 3