I'm trying to set up a 3 containers architecture for a web app (front-end, back-end, database). I created two networks one for the back (database back-end), the other for the front (front back). I am using compose to start the services.
I can't access my front container from my host even though I published a port.
Am I missing something to make it work ?
Here is my docker-compose.yml file.
services:
api:
image: ruby:3.1.2
command: sh -c "rm -f /app/tmp/pids/server.pid && bundle install && rails s"
working_dir: /app
depends_on:
- database
networks:
- back
- front
ports:
- "3000:3000"
volumes:
- type: bind
source: ../api
target: /app
web:
image: node
working_dir: /app
command: sh -c "yarn install && yarn build && yarn dev"
depends_on:
- api
networks:
- front
- host
volumes:
- type: bind
source: ../frontend
target: /app
ports:
- "8000:5173"
database:
image: keinos/sqlite3
networks:
- back
expose:
- "3306"
volumes:
- citrine-db:/db
networks:
back:
driver: bridge
front:
driver: bridge
host:
volumes:
citrine-db:
CodePudding user response:
Based on this:
I get a connection refused when I try accesing ip_address:5173
It sounds like your application is only listening on the localhost address (127.0.0.1
). You need it to listen on "all addresses" (0.0.0.0
). This is why you're able to connect to localhost:5173
from inside the container, but connections from outside the container are failing.