Sarkis Arutiunian
Sarkis Arutiunian

Reputation: 1291

Docker-compose networking, access host port from container

This is my compose file:

version: '3'
services:
  web:
    container_name: dash
    build: 
      context: .
      dockerfile: Dockerfile
      args:
        webpackVersion: 2.2.1
        nodeVersion: "6.x"
    ports:
      - "3036:3036"
    links:
      - mongodb:dbhost
    depends_on:
      - mongodb
  mongodb:
    container_name: mongodb
    build:
      context: .
      dockerfile: Dockerfile-mongodb

Right now web has access to mongodb container where I keep app configs. But I also need to be able access port 3306 on my local machine where I'm running docker-compose, from web.

I tried to follow the documentation, but I'm new in docker so it looks pretty complicated for me, how to use networking in docker-compose.

If any one can help me to understand this I'll be really grateful!

Upvotes: 0

Views: 3910

Answers (1)

Sarkis Arutiunian
Sarkis Arutiunian

Reputation: 1291

I found only one way to open all host ports, is to use network_mode: host it should be also possible by using network but in my case first solution was enough.

version: '3'
services:
  web:
    container_name: dash
    network_mode: host
    build: 
      context: .
      dockerfile: Dockerfile
      args:
        webpackVersion: 2.2.1
        nodeVersion: "6.x"
    ports:
      - "3036:3036"
    links:
      - mongodb:dbhost
    depends_on:
      - mongodb
  mongodb:
    container_name: mongodb
    network_mode: host
    build:
      context: .
      dockerfile: Dockerfile-mongodb

network_mode: host won't work on mac, you should run docker in VB

Upvotes: 2

Related Questions