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"

  • Intellij, Spring dev tools remote, Docker, error Unexpected 404 response uploading class files
  • How can I overcame this 500 Server Internal Error when trying to pull google/appengine-java image for Managed VMs?
  • Dockerfile: RUN command with special parameters
  • container running but cannot be visited in browser
  • Docker Swarm HAProxy Not Load Balancing w/ Overlay Networking
  • Recover docker container's run arguments
  • 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

  • How to run a command on a linked docker container?
  • Deploying Mysql on Mesos using Marathon
  • How to stop power shell script on error?
  • Unable to locate dependency 'class library project(s)'
  • Docker /vfs folder size
  • Google push-to-deploy jenkins image fails after reboot
  • 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.