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"

  • Cannot login with wp-cli generated user wordpress behind reverse proxy
  • CentOS7 Docker login/ pull x509: certificate signed by unknown authority
  • Docker container mongod error when starting via ssh
  • App must be inserted into the docker image?
  • Vagrant ssh to Docker container
  • Rancher and elasticsearch Nest
  • 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

  • Unable to create machine in docker
  • Can't connect to Express server inside Docker container created with docker-compose
  • Could not get page inside of the docker's container
  • Accessing a node.js Hapi server running inside a docker container
  • Send “sigterm” from Java to Bash script
  • iptables not working on macvlan traffic in container
  • 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.