Docker Community Forums

Share and learn in the Docker community.

Different outcome for dockerfile command and direct input

I’m running a proxied browser-sync server through gulp inside an apache docker container. All is working fine, when I start the server manually (starting container, attaching shell, running gulp script) and I can reach the server on the desired port. But when I tell docker to do the ‘gulp’ command for me (either through ‘CMD’ in dockerfile or ‘command’ in docker-compose) the server starts successfully, but is not reachable. The strange thing is, that it’s not just not reachable but timing out. I’ve already tried using ‘RUN’ and ‘ENTRYPOINT’ but same result.

It seems like there is a difference between a command that’s executed through docker and one that’s entered manually (maybe user related stuff). But the output for both is the same:

apache-browsersync_1  | [18:35:01] Using gulpfile /var/www/html/gulpfile.js
apache-browsersync_1  | [18:35:01] Starting 'default'...
apache-browsersync_1  | [Browsersync] Proxying: http://localhost:8080
apache-browsersync_1  | [Browsersync] Access URLs:
apache-browsersync_1  |  ----------------------------------
apache-browsersync_1  |        Local: http://localhost:80
apache-browsersync_1  |     External: http://172.21.0.2:80
apache-browsersync_1  |  ----------------------------------
apache-browsersync_1  |           UI: http://localhost:3001
apache-browsersync_1  |  UI External: http://localhost:3001
apache-browsersync_1  |  ----------------------------------
apache-browsersync_1  | [Browsersync] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false)

Here is my setup:

docker-compose.yml

version: "3"

services:
  ...

  apache-browsersync:
    build:
      context: .
      dockerfile: apache.dockerfile
    volumes:
      - .:/var/www/html/
    ports:
      - 80:80

  ...

dockerfile

FROM php:apache

# change apache port from 80 to 8080
RUN sed -i 's/80/8080/g' /etc/apache2/ports.conf

# install node
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install -y nodejs

# install gulp
RUN npm install gulp-cli -g

# copy project data
COPY . /var/www/html

# install dependencies
RUN npm install

# start gulp
CMD gulp

gulpfile.js

var gulp = require('gulp');
var browserSync = require('browser-sync').create();

function defaultTask() {
  browserSync.init({
    proxy: 'localhost:8080',
    port: 80
  });
}

exports.default = defaultTask;

Apache is stopping, when running gulp in the same container, so I split up both services into different containers and referenced the apache server through the docker-compose container name in my gulp file.