简体   繁体   English

Docker:无法从主机中的浏览器访问容器

[英]Docker: Unable to access container from browser in host machine

I have a docker-compose.yaml to create containers我有一个 docker-compose.yaml 来创建容器

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我在浏览器中输入 192.168.10.10 进行访问,但出现超时错误

In docker-compose file add this line:在 docker-compose 文件中添加这一行:

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

Port is port you would like to expose to outside. Port是您想对外公开的端口。 You can check on host by access URL http://localhost:port您可以通过访问 URL http://localhost:port检查主机

port01 is port which is configure in Dockerfile, its application port. port01是在 Dockerfile 中配置的端口,它的应用程序端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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