Skip to content

Instantly share code, notes, and snippets.

@vxsx
Created October 2, 2017 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vxsx/4186c1fdd8fafddd85759fb55a483931 to your computer and use it in GitHub Desktop.
Save vxsx/4186c1fdd8fafddd85759fb55a483931 to your computer and use it in GitHub Desktop.
Browsersync with Divio cloud projects
# running browsersync inside docker container
# browser sync has to be installed via package.json
# docker-compose.yml
# it might look slightly different in your case, important parts are &WEB label and browsersync section
# the downside is it's not as fast as the one outside host system
web: &WEB
build: .
links:
- "db:postgres"
ports:
- "8000:80"
volumes:
- ".:/app:rw"
- "./data:/data:rw"
command: python manage.py runserver 0.0.0.0:80
env_file: .env-local
browsersync:
<<: *WEB
ports:
# the proxy
- "8001:8001"
# browsersync UI
- "8002:8002"
links:
- "web:web"
command: /node_modules/.bin/browser-sync start --proxy http://web:80/ --port=8001 --ui-port=8002 --files=/app/static/css/*.css,/app/static/js/dist/*.js,/app/templates/**/*.html
db:
image: postgres:9.4
volumes:
- ".:/app:rw"
# running divio project up will spin up both normal localhost:8000 and browser-sync's localhost:8001
# otherwise you can run it separately via docker-compose run --service-ports browsersync,
# but that's not really necessary
# install once
npm install -g browser-sync
# run
# folders may depend on the exact setup, e.g. we only bundle js into the dist folder, if you want to watch all
# it would be `static/js/**/*.js`
browser-sync start --proxy http://0.0.0.0:8000/ --files=static/css/*.css,static/js/dist/*.js,templates/**/*.html
@vxsx
Copy link
Author

vxsx commented Oct 2, 2017

Also depending on the system and version of Docker the "dockerized" version can eat a lot more resources than the one on the host system due to buggy file system events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment