问题
I'm trying to run browsersync in my docker container but I only get the directory listing when I navigate to localhost:3000. I'm trying to run a WordPress instance, and I'm using Gulp as the task runner. localhost:3001 brings up the browsersync ui successfully and viewing localhost (no port) brings up the homepage. Here are the relevant code snippets I think.
Gulpfile BrowserSync settings:
const gBrowsersync = function(done) {
browsersync.init({
open: false,
});
done();
};
Docker-compose:
version: "3.7"
services:
db:
image: mysql:5.7
container_name: db
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- db_data:/var/lib/mysql
networks:
- back
wordpress:
build: .
image: ws-wordpress
container_name: wp
depends_on:
- db
restart: always
ports:
- "80:80"
- "3000:3000"
- "3001:3001"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: password
volumes:
- ./wp-content/:/var/www/html/wp-content/
- ./sw.js:/var/www/html/sw.js
- ./manifest.json:/var/www/html/manifest.json
- ./package.json:/var/www/html/package.json
- ./gulpfile.babel.js:/var/www/html/gulpfile.babel.js
- ./webpack.config.js:/var/www/html/webpack.config.js
networks:
- back
networks:
back:
volumes:
db_data:
Dockerfile:
FROM wordpress
RUN apt-get update -y
RUN apt-get install gnupg -y
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install nodejs -y
RUN apt-get install nano -y
回答1:
Added a proxy option and now it works @ localhost:3000
const gBrowsersync = function(done) {
browsersync.init({
open: false,
proxy: "localhost"
});
done();
};
Not sure why I had to add localhost as a proxy though. If anyone can provide a brief explanation, I would appreciate it.
来源:https://stackoverflow.com/questions/53819999/docker-and-browsersync