JVG
JVG

Reputation: 21170

Docker Compose: Accessing my webapp from the browser

I'm finding the docs sorely lacking for this (or, I'm dumb), but here's my setup:

Webapp is running on Node and Express, in port 8080. It also connects with a MongoDB container (hence why I'm using docker-compose).

In my Dockerfile, I have:

FROM node:4.2.4-wheezy

# Set correct environment variables.
ENV HOME /root

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/
RUN npm install;

# Bundle app source
COPY . /usr/src/app

CMD ["node", "app.js"]

EXPOSE 8080

I run:

docker-compose build web
docker-compose build db
docker-compose up -d db
docker-compose up -d web

When I run docker-machine ip default I get 192.168.99.100.

So when I go to 192.168.99.100:8080 in my browser, I would expect to see my app - but I get connection refused.

What silly thing have I done wrong here?

Upvotes: 5

Views: 5492

Answers (1)

Tkwon123
Tkwon123

Reputation: 4150

Fairly new here as well, but did you publish your ports on your docker-compose file?

Your Dockerfile will simply expose the ports but not open access to your host. Publishing (with the -p flag on a docker run command or ports on a docker-compose file. Will enable access from outside the container (see ports in the docs) Something like this may help:

ports:
  - "8080:8080"

Upvotes: 7

Related Questions