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"

  • Docker for mac does not pull any image
  • Requirement to accept network packets in container from host or outside? (docker port forwarding)
  • Docker and Julia - how to get .jl files to run inside a container
  • Docker Compose Dev and Production Environments Best Workflow
  • External properties file using Spring Boot and Docker
  • Docker flask uwsgi 404 on a remote host
  • 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

  • docker daemon exec: “dockerd” : executable not found in %PATH%
  • Docker Error getting events from daemon: EOF
  • How to place files on shared volume from within Dockerfile?
  • How to pull private docker image from docker to new machine
  • Dockerize Multi Module Maven Project
  • Service and Replication controller
  • 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.