2

I've been trying to figure out why I cannot containers using "localhost:3000" from host. I've tried installing Docker via Homebrew, as well as the Docker for Mac installer. I believe I have the docker-compose file configured correctly.

Here is the output from docker-compose ps

           Name                         Command               State                       Ports
--------------------------------------------------------------------------------------------------------------------
ecm-datacontroller_db_1      docker-entrypoint.sh postgres    Up      0.0.0.0:5432->5432/tcp
ecm-datacontroller_kafka_1   supervisord -n                   Up      0.0.0.0:2181->2181/tcp, 0.0.0.0:9092->9092/tcp
ecm-datacontroller_redis_1   docker-entrypoint.sh redis ...   Up      0.0.0.0:6379->6379/tcp
ecm-datacontroller_web_1     npm start                        Up      0.0.0.0:3000->3000/tcp

Here is my docker-compose.yml

version: '2'
services:
  web:
    ports:
      - "3000:3000"
    build: .
    command: npm start
    env_file: .env
    depends_on:
      - db
      - redis
      - kafka
    volumes:
      - .:/app/user
  db:
    image: postgres:latest
    ports:
      - "5432:5432"
  redis:
    image: redis:alpine
    ports:
      - "6379:6379"
  kafka:
    image: heroku/kafka
    ports:
      - "2181:2181"
      - "9092:9092"

I cannot access any ports that are exposed by docker-compose with curl localhost:3000 I get the following result from that

curl: (52) Empty reply from server

I should be getting {"hello":"world"}.

Dockerfile:

FROM heroku/heroku:16-build

# Which version of node?
ENV NODE_ENGINE 10.15.0
# Locate our binaries
ENV PATH /app/heroku/node/bin/:/app/user/node_modules/.bin:$PATH

# Create some needed directories
RUN mkdir -p /app/heroku/node /app/.profile.d
WORKDIR /app/user

# Install node
RUN curl -s https://s3pository.heroku.com/node/v$NODE_ENGINE/node-v$NODE_ENGINE-linux-x64.tar.gz | tar --strip-components=1 -xz -C /app/heroku/node

# Export the node path in .profile.d
RUN echo "export PATH=\"/app/heroku/node/bin:/app/user/node_modules/.bin:\$PATH\"" > /app/.profile.d/nodejs.sh

ADD package.json /app/user/
RUN /app/heroku/node/bin/npm install
ADD . /app/user/

EXPOSE 3000

Anyone have any ideas?

  • On mac you can check if anyone is listening on ports : `lsof -i`. Do you see these ports opened? – brokenfoot Jan 10 '19 at 23:01
  • Hmm.. No I do not. None of those ports show up on ```lsof -i```. I'm now wondering if Docker doesn't have access to open ports. – Justin R. Donaruma Jan 10 '19 at 23:05
  • You can reduce your yml file to just one service and see if that port is actually opened. – brokenfoot Jan 10 '19 at 23:19
  • share your Dockerfile please – Yegor Jan 10 '19 at 23:42
  • 1
    That's similar to the symptom of the process inside the container binding to 127.0.0.1 and being unreachable from outside the container (rather than binding to 0.0.0.0; this is printed in startup-time log messages). Compare for example [Docker ports are not exposed](https://stackoverflow.com/questions/35414479/docker-ports-are-not-exposed). – David Maze Jan 10 '19 at 23:58
  • @Egor - Updated the Dockerfile. – Justin R. Donaruma Jan 11 '19 at 01:51
  • @DavidMaze - This ended up being it. Fastify defaults to 127.0.0.1 instead of 0.0.0.0. fixing that, resolved my issue. Thank you. – Justin R. Donaruma Jan 11 '19 at 01:57

1 Answers1

1

Ultimately, I ended up having a service that was listening on 127.0.0.1 instead of 0.0.0.0. Updating this resolved the connectivity issue I was having.