How to access external port in docker-compose

11/6/2019

I would like to use my docker-compose config for development purposes and run frontend, backend, nginx for routing services to run and start together. For now I'm using also kubernetes port-forwarding in order to get to my neo4j db. What I want to achieve is to use mapped port inside docker containers, ie. external port should be also visible inside the docker. It runs without docker smoothly but cannot inside containers. My docker-compose file looks like this, nothing fancy:

version: '3'

networks:
  lan:

services:
  nginx:
    restart: always
    build:
      dockerfile: Dockerfile.dev
      context: ./nginx
    ports:
      - 3050:80
    depends_on:
      - client
      - api

  client:
    build:
      context: ./client
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - ./client:/app

  api:
    build:
      context: ./
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - ./:/app
    environment:
      - REACT_APP_NEO4J_HOST=neo4j://neo4j:password@localhost:7687
      - REACT_APP_NEO4J_LOGIN=neo4j
      - REACT_APP_NEO4J_PASS=password

Unfortunately I'm getting error as it is not forwarder inside my docker api container. To forward the port I'm using (after getting authenticated): kubectl port-forward svc/neo4j-ee-neo4j 7687:7687 but of course it is only available on my host.

-- Murakami
docker
docker-compose
kubernetes

1 Answer

11/6/2019

add network_mode: "host" to the service properties, so it will share the host interface. https://docs.docker.com/compose/compose-file/#network_mode

-- Efrat Levitan
Source: StackOverflow