Unable to connect container port from localhost when network_mode: “bridge” (docker-compose)

This is my docker-compose.yml

yml
version: '2'
services:
admin_db:
build:
context: .
dockerfile: postgres.dockerfile
args:
- DB_NAME=admin_db
- DB_USER=admin
- DB_PASSWORD=admin_pass
network_mode: "default"
admin:
build:
context: .
dockerfile: admin.dockerfile
args:
- UID=$UID
- GID=$GID
- UNAME=$UNAME
command: /bin/bash
depends_on:
- admin_db
ports:
- "8000:8000"
links:
- admin_db
network_mode: "bridge"

  • How to configure docker registry always up and running when configured with redis?
  • Is there any way to find out who pushed an image with a specific tag to a repo on hub.docker.com?
  • Docker for Azure - no swarm mode?
  • docker executable file not found in $PATH
  • Docker Compose: deploying different services from docker-compose.yml to different set of hosts
  • Basic elasticsearch tribe setup with docker
  • If with networking_mode:”bridge” I should be able to access my app (admin) on http://127.0.0.1:8000/ from localhost, but currently, I’m able to access it only on random-ip:8000 from localhost.
    I’m able to http://127.0.0.1:8000/ access when networking_mode is “host”, but then I’m unable to link containers.
    Is there any solution to have both things ?
    – linked containers
    – app running on http://127.0.0.1:8000/ from localhost

  • Bluemix very slow to start Spring Boot application, hangs
  • Docker is installed but Docker Compose is not ? why?
  • Web development transition from MAMP to Docker
  • Why does docker mount a file with a numeric value as a directory?
  • How to completely reinstall Docker on Windows
  • Connection refused: PHPUnit selenium in Docker
  • One Solution collect form web for “Unable to connect container port from localhost when network_mode: “bridge” (docker-compose)”

    If for some unknown reason normal linking doesn’t work you can always create another bridged network and connect directly to that docker image. By doing that IP address of that running image will always be the same.

    I would edit it like this:

    version: '2'
    services:
      admin_db:
        build:
          context: .
          dockerfile: postgres.dockerfile
          args:
            - DB_NAME=admin_db
            - DB_USER=admin
            - DB_PASSWORD=admin_pass
        networks:
          back_net:
            ipv4_address: 11.0.0.2
    
      admin:
        build:
          context: .
          dockerfile: admin.dockerfile
          args:
            - UID=$UID
            - GID=$GID
            - UNAME=$UNAME
        command: /bin/bash
        depends_on:
          - admin_db
        ports:
          - "8000:8000"
        extra_hosts:
          - "admin_db:11.0.0.2"
        networks:
          back_net:
            ipv4_address: 11.0.0.3
    
    networks:
      back_net:
        driver: bridge
        driver_opts:
          com.docker.network.enable_ipv6: "false"
          com.docker.network.bridge.name: "back"
        ipam:
          driver: default
          config:
            - subnet: 11.0.0.0/24
              gateway: 11.0.0.1
    

    Hope that helps.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.