Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Compose port issue. Cannot launch docker project on localhost

I am on a mac (El Capitan, stable, 10.11.6) with Docker Desktop for Mac stable installed.

I am running a simple javascript app on the official node image. Here's what the Dockerfile looks like:

FROM node

WORKDIR /usr/local/src

And here's the docker-compose.yml:

version: '2'

services:
  web:
    container_name: myproject_dev
    build: .
    command: npm run development
    ports:
     - "1234:8000"
     - "1235:8080"
     - "80:80"
    volumes:
      - ./my-project:/usr/local/src

Running docker-compose up starts everything normally:

myproject_dev | http://localhost:8080/webpack-dev-server/
myproject_dev | webpack result is served from /assets/
myproject_dev | content is served from /usr/local/src

And docker ps shows that the ports are mapped:

CONTAINER ID        IMAGE                        COMMAND                 CREATED             STATUS              PORTS                                                                NAMES
820694f618b4        myproject_web   "npm run development"   20 minutes ago      Up 20 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:1234->8000/tcp, 0.0.0.0:1235->8080/tcp   myproject_dev

But I am unable to see the project page on the browser (using localhost:1234). Works fine when I run the project outside the docker. So, an issue with the project is ruled out.

Tried the following:

  1. use a different node docker
  2. switch between docker beta and stable versions
  3. stop all host apache/nginx services

But no luck :( What am I missing here?

like image 549
fenderplayer Avatar asked Dec 24 '22 02:12

fenderplayer


1 Answers

The service you're running is only listening to the containerlocalhost interface, so nothing outside the container can access it. It needs to listen on 0.0.0.0.

like image 88
dnephin Avatar answered Dec 26 '22 15:12

dnephin