1

I've got a node app that I can run locally using npm run. It is using express as the server and uses browser sync to show hot reloads.

Express is using port 6001
Browsersync is using ports 3000 and 3001

Docker file

FROM node/argon

WORKDIR /usr/src/app

COPY package.json /usr/src/app/
RUN npm install
ENV PATH /usr/src/app/node_modules/.bin:$PATH

USER app
COPY . /usr/src/app
RUN sudo chown -R app /usr/src/app
RUN npm start
EXPOSE 6001
CMD ["npm", "start"]

docker-compose.yml

web:
  extends:
    file: docker-compose-base.yml
    service: web
  ports:
    - "6001:6001"
  environment:
    VIRTUAL_HOST: testing.docker

docker-compose-base.yml

web: 
  build: .
  command: npm start
  volumes:
    - .:/usr/src/app
    - /usr/src/app
    - /usr/src/app/node_modules

I can run docker-compose build and it builds just fine, running docker-compose up spits out the following:

[BS] Access URLs:
 ----------------------------
 Local: http://localhost:3000
 ----------------------------
    UI: http://localhost:3001
 ----------------------------
Listening on http://localhost:6001

But accessing http://testing.docker appears as though the container never mounted. Running docker-compose ps shows no containers, but running docker ps shows the container is available.

I'm completely at a loss.

3
  • Did you use docker-compose up to start the containers? Commented Aug 4, 2016 at 15:25
  • Yes, that's what generated the "listening" logs. Commented Aug 4, 2016 at 15:26
  • Try docker-compose up -d and then docker-compose ps in that directory, as well as docker ps to see if they return anything. Also try curl localhost:6001 to check if port mapping is correct. Commented Aug 4, 2016 at 15:31

2 Answers 2

1

I assume you have "testing.docker" host entry set up somewhere your browser can resolve, change the format for that entry to:

environment:
  - VIRTUAL_HOST=testing.docker

You would also need to expose ports 3000 and 3001 to get the browser-sync working:

ports:
  - "6001:6001"
  - "3000:3000"
  - "3001:3001"

And as mentioned, use docker-compose up -d if you want to detach the containers to run them in the background. If you are quitting the output in the same terminal window as you are checking docker-compose ps and not detaching, the containers will not be running. If you do check in a separate window, make sure you are in the right directory and/or using a --project-name in your compose commands.

Sign up to request clarification or add additional context in comments.

1 Comment

I think normally your solution would work, however there was a key component missing in this - I forgot about the fact that I'm using dinghy.
0

I missed a key part of the equation here: I am using dinghy to manage the containers and it needs a port to forward to.

So that changes the files to look like this:

Dockerfile

FROM node/argon

RUN echo 08-03-2016 > last_docker_cache_bust

EXPOSE 6001

WORKDIR /usr/src/app

COPY package.json .npmrc* /usr/src/app/
RUN npm install
ENV PATH /usr/src/app/node_modules/.bin:$PATH

ADD . /usr/src/app
RUN sudo chown -R app /usr/src/app

docker-compose.yml

web:
  extends:
    file: docker-compose-base.yml
    service: web
  ports:
    # The first port is managed by dinghy, the second is the app's running port for express
    - "7510:6001"
  environment:
    VIRTUAL_HOST: testing.docker

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.