Friday 5 May 2017

docker(Mac/Windows): how to access host machine service from the container?

I can access the host machine's services from inside a docker container using --network="host" option in docker run command. This works well on Ubuntu. The same command, though, isn't working on Mac OS Sierra(10.12.4) and Windows 10.

My use case is that I have a local mongoDB server running on mongodb://127.0.0.1:27017. I spin up my container using the following command:

docker run -p 3002:3002 --network="host" image-name

Dockerfile:

FROM node:7.5

RUN npm install -g pm2

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

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

COPY . /usr/src/app

EXPOSE 3002

ENV NODE_ENV local

CMD pm2 start --no-daemon server.js

I have tried using --net="host" option both on Mac and Windows. It doesn't work. Please help.



via chaudharyp

No comments:

Post a Comment