Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port bindings fail on Docker for Mac #4783

Closed
c-Monster opened this issue May 1, 2017 · 18 comments
Closed

Port bindings fail on Docker for Mac #4783

c-Monster opened this issue May 1, 2017 · 18 comments

Comments

@c-Monster
Copy link

I specify the port bindings in the docker-compose-build.yml, but when I run docker-compose, and docker-ps there is no listing for any ports, nor can I hit them with Postman.

@shin-
Copy link

shin- commented May 1, 2017

You might want to try sharing the contents of you YAML files and the command you're executing.

@c-Monster
Copy link
Author

c-Monster commented May 1, 2017

I run the commands:
docker-compose -f docker-compose-build.yml build
docker-compose -f docker-compose-build.yml up -d

Here's the file:

services:
    av-api:
        build:
            context: .
            dockerfile: Dockerfile-development
        ports:
            - "8000:8000"
        environment:
            - PI_HOSTNAME=$PI_HOSTNAME
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
            - CONFIGURATION_DATABASE_MICROSERVICE_ADDRESS=$CONFIGURATION_DATABASE_MICROSERVICE_ADDRESS
            - ELASTIC_API_EVENTS=$ELASTIC_API_EVENTS
        network_mode: "host"
        restart: always
    crestron-control-microservice:
        build: 
            context: ../crestron-control-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8004:8004"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
        network_mode: "host"
        restart: always
    pjlink-microservice:
        build: 
            context: ../pjlink-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8005:8005"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
            - PJLINK_PORT=$PJLINK_PORT
            - PJLINK_PASS=$PJLINK_PASS
        network_mode: "host"
        restart: always
    configuration-database-microservice:
        build: 
            context: ../configuration-database-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8006:8006"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
            - CONFIGURATION_DATABASE_USERNAME=$CONFIGURATION_DATABASE_USERNAME
            - CONFIGURATION_DATABASE_PASSWORD=$CONFIGURATION_DATABASE_PASSWORD
            - CONFIGURATION_DATABASE_HOST=$CONFIGURATION_DATABASE_HOST
            - CONFIGURATION_DATABASE_PORT=$CONFIGURATION_DATABASE_PORT
            - CONFIGURATION_DATABASE_NAME=$CONFIGURATION_DATABASE_NAME
        network_mode: "host"
        restart: always
    sony-control-microservice:
        build: 
            context: ../sony-control-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8007:8007"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
            - SONY_TV_PSK=$SONY_TV_PSK
        network_mode: "host"
        restart: always
    london-audio-microservice:
        build: 
            context: ../london-audio-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8009:8009"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
        network_mode: "host"
        restart: always
    cgi-microservice:
        build: 
            context: ../cgi-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8010:8010"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
        network_mode: "host"
        restart: always
    pulse-eight-neo-microservice:
        build: 
            context: ../pulse-eight-neo-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8011:8011"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
        network_mode: "host"
        restart: always
    adcp-control-microservice:
        build: 
            context: ../adcp-control-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8012:8012"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
        network_mode: "host"
        restart: always
    av-api-rpc:
        build: 
            context: ../av-api-rpc
            dockerfile: Dockerfile-development
        ports:
            - "8100:8100"
        environment:
            - PI_HOSTNAME=$PI_HOSTNAME
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
            - CONFIGURATION_DATABASE_MICROSERVICE_ADDRESS=$CONFIGURATION_DATABASE_MICROSERVICE_ADDRESS
            - ELASTIC_API_EVENTS=$ELASTIC_API_EVENTS
        network_mode: "host"
        restart: always
    touchpanel-ui-microservice:
        build: 
            context: ../touchpanel-ui-microservice
            dockerfile: Dockerfile-development
        ports:
            - "8888:8888"
        environment:
            - PI_HOSTNAME=$PI_HOSTNAME
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
        network_mode: "host"
        restart: always
    configuration-database-tool:
        build: 
            context: ../configuration-database-tool
            dockerfile: Dockerfile
        ports:
            - "9999:9999"
        environment:
            - LOCAL_ENVIRONMENT=$LOCAL_ENVIRONMENT
            - CONFIGURATION_DATABASE_MICROSERVICE_ADDRESS=$CONFIGURATION_DATABASE_MICROSERVICE_ADDRESS
        network_mode: "host"
        restart: always```

@c-Monster
Copy link
Author

c-Monster commented May 1, 2017

docker version and docker-compose version output:

 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Tue Mar 28 00:40:02 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:00:50 2017
 OS/Arch:      linux/amd64
 Experimental: false 

docker-compose version 1.12.0, build b31ff33
docker-py version: 2.2.1
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016 

@shin-
Copy link

shin- commented May 4, 2017

Why are you setting everything to use the host network mode?
Port bindings are not going to show up in docker ps when you do that because they aren't created in the first place.

@inancgumus
Copy link

@c-Monster any progress on this?

@c-Monster
Copy link
Author

@shin- I'm setting everything to network host because the containers need to talk to each other on localhost
@inancgumus not as of yet, but I'm going to try running Docker in xhyve to see if that changes anything

@shin-
Copy link

shin- commented May 12, 2017

Okay, but port bindings aren't applied when networking directly on the host, so what you're seeing is expected behavior. See: https://docs.docker.com/engine/userguide/networking/

The host network adds a container on the host’s network stack. As far as the network is concerned, there is no isolation between the host machine and the container. For instance, if you run a container that runs a web server on port 80 using host networking, the web server is available on port 80 of the host machine.

@paul-ovchinnikov
Copy link

paul-ovchinnikov commented May 16, 2017

Hi there!
I have the same issue on Mac with docker-compose.yml

version: '3'
services:
  db:
    build:
      context: ./db
      dockerfile: Dockerfile
    image: db
    ports:
      - "3307:3306"
    volumes:
      - demo_volume:/var/lib/mysql
    networks:
      - my-backend

  web:
    build:
      context: ./web
      dockerfile: Dockerfile
    image: web
    depends_on:
      - db
    ports:
      - "18080:8080"
    networks:
      - my-backend
    environment:
      - DATABASE_HOST=db
      - DATABASE_USER=user
      - DATABASE_PASSWORD=password
      - DATABASE_NAME=demo
      - DATABASE_PORT=3307
      - SPRING_PROFILES_ACTIVE=container
      - DEBUG=true

volumes:
  demo_volume:
    driver: local

networks:
  my-backend:
    driver: bridge

web service can't connect to db service via 3307 exposed port. But can connect with internal container 3306 port

@paul-ovchinnikov
Copy link

paul-ovchinnikov commented May 16, 2017

MBP-Paul:docker-dir paul$ docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
918492b54d2e        web              "java -Xmx200m -Dj..."   10 minutes ago      Up 10 minutes       0.0.0.0:18080->8080/tcp   dockerdir_web_1
1f877c18d883        db                  "docker-entrypoint..."   10 minutes ago      Up 10 minutes       0.0.0.0:3307->3306/tcp    dockerdir_db_1

ports looks like exposed but web can't connect to db:3307

@inancgumus
Copy link

inancgumus commented May 16, 2017

@shin For this repo's examples, they're using host networking and as I see. It doesn't work the other way around. I tried some other network types but no luck yet. And, I can't connect to the services for the exposed ports with host networking, because, it binds the ports not to the localhost. As I see, this is a problem on OS X.

@paul-ovchinnikov Whick Docker version you're using?

@paul-ovchinnikov
Copy link

paul-ovchinnikov commented May 16, 2017

@inancgumus the latest version (docker version):

Client:
 Version:      17.03.1-ce
 API version:  1.27
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Tue Mar 28 00:40:02 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.03.1-ce
 API version:  1.27 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   c6d412e
 Built:        Fri Mar 24 00:00:50 2017
 OS/Arch:      linux/amd64
 Experimental: true

docker-compose version:

docker-compose version 1.11.2, build dfed245
docker-py version: 2.1.0
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016

@shin-
Copy link

shin- commented May 16, 2017

@inancgumus That repo's README specifically says it is not compatible with Docker for Mac (or any setup where the Docker Engine does not live directly on the host, e.g. in a virtual machine). I'd recommend creating an issue on the https://github.com/docker/for-mac repo.

@paul-ovchinnikov When you use a non-bridge network, the exposed port is only for accessing the container from your host. Containers that are part of the same network interact on their internal ports. This is normal behavior.

@inancgumus
Copy link

inancgumus commented May 16, 2017

@shin- Yeah, I know that, thx anyway. I and others have also opened many issues there already. I was trying to find non-official solution. There are several hacky attempts already trying to fix it. Docker for Mac is not enough for some purposes yet. Docker Linux support is better.

@shin-
Copy link

shin- commented May 16, 2017

The non-Linux experience has made great strides in the past couple years, but containers are unfortunately not a native feature on OS X.

@inancgumus
Copy link

inancgumus commented May 16, 2017

@shin- Yeah, the progress so far is good but not enough. Instead of waiting for the full support for OS X like Linux, I'm developing on my own Docker network, with a linux based docker-machine.

@paul-ovchinnikov
Copy link

@shin- I use custom network with bridge driver. See in the end of my docker-compose.yml

@shin-
Copy link

shin- commented May 17, 2017

@paul-ovchinnikov My bad - "non-bridge" in my previous message referred to any network that are not the (default) network named bridge. My comment still applies to any user-created network, even if they use the "bridge" driver.

@paul-ovchinnikov
Copy link

paul-ovchinnikov commented May 18, 2017

@shin- Thanks! Now it's clear. And this behavior explained in docker doc - networking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants