Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
616 views
in Technique[技术] by (71.8m points)

configuration - How do I configure docker compose to expose ports correctly?

I'm using docker and docker compose to run a clojure and a node app, alongside postgres.

The project is contained in the following folder structure.

project/
-- app/
-- -- Dockerfile
-- frontend/
-- -- /Dockerfile
-- docker-compose.yml

The app/Dockerfile looks like so...

FROM clojure:latest
COPY . /usr/src/app
WORKDIR /usr/src/app

EXPOSE 9000

CMD ["lein", "run", "migrate", "&&","lein", "run"]

The frontend/Dockerfile looks like so ...

FROM node:5
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN npm install

EXPOSE 8080

CMD ["npm", "start"]

And lastly the docker-compose.yml looks like...

frontend:
  image: bradcypert/node
  volumes:
    - ./frontend:/usr/src/frontend
  ports:
    - "8080:8080"

backend:
  image: bradcypert/clojure
  volumes:
    - ./app:/usr/src/backend
  ports:
    - "9000:9000"
  links:
    - postgres

postgres:
  image: postgres
  ports:
    - "5432:5432"

backend is failing for a separate reason, but the frontend seems to be running successfully, that being said, I'm unable to hit localhost:8080 and see the app. What do I need to do make this happen?

Thanks in advance.

Just to clarify, the command being run is docker-compose up

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With boot2docker (on Mac or Windows), to access any port from localhost, you have to configure your VirtualBox VM in order to port-forward that port from the VM into the host.

Your port mappings are correct, but you still need to make visible to your host (Mac) the one port you want to access from localhost (your Mac).

See for instance "Using boot2docker to run Docker on a Mac or Windows" from Andrew Odewahn:

enter image description here

That way, you don't have to find out what the IP of your machine is.
(Which you can see with docker-machine ls followed by docker-machine ip <name>)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...