Docker和BrowserSync

时间:2018-12-17 17:10:26

标签: wordpress docker gulp browser-sync

我试图在docker容器中运行browsersync,但是当我导航到localhost:3000时,我只会得到目录列表。我正在尝试运行WordPress实例,并且正在使用Gulp作为任务运行程序。 localhost:3001成功启动浏览器同步ui,查看localhost(无端口)打开主页。这是我认为的相关代码段。

Gulpfile BrowserSync设置:

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

2 个答案:

答案 0 :(得分:1)

我还没有更改browsersync,但是我需要像这样公开端口: 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

答案 1 :(得分:0)

添加了一个代理选项,现在可以在@localhost:3000上使用

const gBrowsersync = function(done) {
  browsersync.init({
    open: false,
    proxy: "localhost"
  });
  done();
};

虽然不确定为什么我必须添加localhost作为代理。如果有人可以提供简短的解释,我将不胜感激。