Docker Community Forums

Share and learn in the Docker community.

Container port unreachable from host though mapped/exposed


(Mcsvenster) #1

Hi there,

we are trying to set up a rails app and built two containers - one with the app and one with the db. The connection between the containers works fine, but I cannot reach my app from the host:

Verbindungsaufbau zu 0.0.0.0:3000 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … Lesefehler (Die Verbindung wurde vom Kommunikationspartner zurückgesetzt) beim Vorspann (header).
Erneuter Versuch

In english something like:
connection to 0.0.0.0:3000 … connected
http request sent waiting for answer … read error (connection resetted by peer) at header
re-trying

The Port seems to be exposed, as ‘container ls’ shows:

CONTAINER ID   ...  PORTS
b69e506f8a84   ...  0.0.0.0:3000->3000/tcp

Our docker-compose.yml:

version: '3.4'
services:
  didpdb:
    image: mariadb:10.3
    volumes:
      - ./tmp/db:/var/lib/mysql
    networks:
      - dbconnection
    environment:
      MYSQL_ROOT_PASSWORD: whatever
  didpapp:
    build: .
    command: bundle exec rails s
    networks:
      - dbconnection
    ports:
      - '3000:3000'
    depends_on:
      - didpdb
networks:
  dbconnection:
    driver: bridge

Linux Mint 19
Docker version 18.06.1-ce, build e68fc7a
docker-compose version 1.17.1, build unknown

It’s funny, that the db-container exposes its port 3306 to the host, though it is not defined in the docker-compose.yml. I can see it with a portscan. But the app container’s ports are all closed according to the scan.

Can anyone point us to the right direction?

Thanks in advance.


(Xoroz) #2

the port 3306 is the default port of the mariadb service, you should do
ports:

  • ‘3000:3306’

the first value is your HOST second is your CONTAINER


(Mcsvenster) #3

Thank’s for your answer, but this has nothing to do with our problem.

Maybe I wasn’t clear on what I want to achieve. I have two containers: one with the app and another one with the db. I want to reach the app through port 3000. Therefor I mapped the container’s port 3000 to the host’s port 3000 with

ports:
  - '3000:3000'

But the app’s container cannot be reached from the host via port 3000.

I can reproduce this on several PCs.

So the question is: How can I make the app, listening on port 3000, accessible from my host machine? What am I missing?


Docker stack container cannot reach LAN (AD) - help