Container port unreachable from host though mapped/exposed

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.

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

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?

Has this ever been answered? I have basically the same issue, but much simpler:

version: '3'

services:
  sshd:
    image: ubuntu
    command: sh -c "/usr/sbin/sshd -ddd"
    expose:
      - "22"
    ports:
      - "0.0.0.0:2022:22"

From my host:

rfb@rfb:/tmp$ ssh -p 2022 localhost
kex_exchange_identification: Connection closed by remote host
Connection closed by 127.0.0.1 port 2022

There isn’t anything particular in my host’s IPTABLES that would make this complicated. I can do the same with a regular docker container, and access it (via the external IP address of the container).