Rice_Crisp
Rice_Crisp

Reputation: 1261

Docker and BrowserSync

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

Upvotes: 2

Views: 3148

Answers (2)

Tyrone
Tyrone

Reputation: 43

I havent changed the browsersync but I needed to expose the port like this: docker-compose.foundation.yaml

version: '3.6'
#ddev-ext-foundation
services:

  web:    
    ports:
      - "127.0.0.1:$DDEV_HOST_WEBSERVER_PORT:8000"
    environment:
      -  HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILHOG_PORT}:8025,8000

Upvotes: 1

Rice_Crisp
Rice_Crisp

Reputation: 1261

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.

Upvotes: 2

Related Questions