简体   繁体   中英

Docker: Unable to access container from browser in host machine

I have a docker-compose.yaml to create containers

version: '2.4'

app:
    hostname: app
    build: .
    environment:
      PYTHONUNBUFFERED: 1
      PYTHONDONTWRITEBYTECODE: 1
    networks:
      app_net:
        ipv4_address: 192.168.10.10
    user: "root:root"

    command: /bin/bash -c "tail -f /dev/null"

networks:
  app_net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 192.168.10.0/24
          gateway: 192.168.10.1
  outside:
    external: true

I successfully created a container but unable to access the app through a browser in a host machine.

I typed 192.168.10.10 in browser to access but it made timeout error

In docker-compose file add this line:

app:
    hostname: app
    build: .
    ports:
    - "port:port01"

Port is port you would like to expose to outside. You can check on host by access URL http://localhost:port

port01 is port which is configure in Dockerfile, its application port.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM