【问题标题】:Docker container is not reachable when generated with docker-compose使用 docker-compose 生成 Docker 容器时无法访问
【发布时间】:2020-12-04 15:06:57
【问题描述】:

我在 ubuntu 20.04 服务器上测试 docker 19.03

当我启动一个 nginx 容器时

docker run --name nginx2 -p 80:80 --rm nginx 

一切正常:可以使用 Ubuntu 服务器的 ip 访问网络服务器

但是当我用 docker-compose 启动容器时

services:
  nginxProxy:
    container_name: nginxProxy
    image: nginx:latest
    ports:
      - '80:80'

网络服务器没有响应


我解决了这个问题:它与netplan有关,在这里找到了解决方案https://github.com/docker/for-linux/issues/924

完成对我的设置的描述:

  • 我使用包 docker.io(来自 ubuntu)安装了第一个 docker,并发现了暴露的问题。
  • 我现在从头开始重新安装了我的 Ubuntu 20.04,并使用包 docker-ce(来自 docker)安装了 docker,但无法连接到任何容器。 docker0 网桥已关闭。

我的网络计划是

network:
    version: 2
    ethernets:
      mainif:
        match:
          name: '*'
        dhcp4: yes

我将其更改为(源中描述的,有 2 个带有 eno1 和 eno2 的 nic)

network:
    version: 2
    ethernets:
      mainif:
        match:
          name: 'en*'
        dhcp4: yes

现在一切正常

【问题讨论】:

  • 请将docker-compose up 的输出添加到您的问题中。
  • 使用默认驱动创建网络“proxynet_default”
    创建nginxProxy ...完成
    附加到nginxProxy
    nginxProxy | /docker-entrypoint.sh:/docker-entrypoint.d/不为空,会尝试执行配置
    /docker-entrypoint.sh:在 /docker-entrypoint.d/
    10-listen-on-ipv6-by-default.sh:获取/etc/nginx/conf.d/default.conf的校验和
    /docker-entrypoint.sh:配置完成;准备启动`
  • 用 docker-compose up -d 运行它

标签: docker networking docker-compose


【解决方案1】:

尝试在docker-compose.yml 的顶部添加版本选项。我刚刚在 Ubuntu 20.04 上尝试过,它打开了默认的 Nginx 登录页面。这是我使用的文件:

version: "3"
services:
  nginxProxy:
    container_name: nginxProxy
    image: nginx:latest
    ports:
      - '80:80'

此外,您粘贴的输出听起来像预期的那样工作。我不知道您在哪里运行服务器,但它也可能与某些防火墙问题或配置错误有关。根据@Rezwan 的建议,为了不实时跟踪正在发生的事情,请添加-d 选项:

docker-compose up -d

并尝试通过在浏览器中键入其 IP 地址来访问 Web 服务器。这是我的设置的日志输出:

Creating nginxProxy ... done
Attaching to nginxProxy
nginxProxy    | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginxProxy    | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
nginxProxy    | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginxProxy    | 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
nginxProxy    | 10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
nginxProxy    | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginxProxy    | /docker-entrypoint.sh: Configuration complete; ready for start up
nginxProxy    | ip.add.re.ss- - [04/Dec/2020:22:28:37 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" "-"

【讨论】:

  • 抱歉,我只复制了部分 docker-compose.yaml,文件中已经有版本:“3”。
猜你喜欢
  • 2020-09-30
  • 1970-01-01
  • 2019-11-14
  • 2020-10-18
  • 1970-01-01
  • 2021-07-19
  • 1970-01-01
  • 2021-04-10
  • 2019-10-05
相关资源
最近更新 更多