清漆和wordpress之间的Docker链接不起作用

时间:2017-03-25 09:00:53

标签: wordpress docker docker-compose varnish

这是我的docker-compose文件:

version: '2'

services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_PASSWORD: wordpress

   varnish:
     image: eeacms/varnish
     depends_on:
       - wordpress
     ports:
       - 9000:6081
     environment:
       DNS_ENABLED: "true"
       BACKENDS: wordpress
       BACKENDS_PORT: 80
volumes:
    db_data:

wordpress 正在0.0.0.0:8080172.17.0.1:8080上运行

但是清漆容器的 / etc / hosts 就像这样

root@4cc3dc214d69:/# cat /etc/hosts
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3  wordpress fd3f01c29d6a dockoor_wordpress_1
172.17.0.3  wordpress_1 fd3f01c29d6a dockoor_wordpress_1
172.17.0.3  dockoor_wordpress_1 fd3f01c29d6a
172.17.0.4  4cc3dc214d69

清漆将 wordpress 映射到 172.17.0.3 这就是为什么在尝试访问0.0.0.0:8000时我得到了

Error 503 Backend fetch failed

Backend fetch failed
Guru Meditation:

XID: 3

Varnish cache server

有人可以指出我的撰写文件有什么问题吗?

P.S docker-compose日志显示清漆确实击中了worpress,但它获得了302响应。

02 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:19 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:20 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:21 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:22 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:23 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:24 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:25 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:26 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:27 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:29 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:30 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:31 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:32 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:33 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:34 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:35 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:36 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:37 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:38 +0000] "GET / HTTP/1.1" 302 338 "-" "-"
wordpress_1     | 172.17.0.4 - - [25/Mar/2017:10:45:39 +0000] "G

1 个答案:

答案 0 :(得分:2)

您的链接似乎按预期工作。 0.0.0.0不是您连接的IP地址,这是一个侦听器IP,它告诉网络堆栈侦听所有接口而不是主机上的特定IP。在您的情况下,所有IP包括127.0.0.1(容器内的环回)和172.17.0.3(该网络上的其他容器可以访问的IP。

请注意,链接在很大程度上已弃用,最好在网络上配置容器(默认网桥除外),并使用内置的DNS发现。同样,compose版本1文件格式也在很大程度上已弃用,您应该考虑升级到至少版本2的撰写文件格式。使用该格式,默认情况下将为容器创建一个网络进行通信。

以下是第2版格式的撰写文件示例:

version: '2'
services:
  wordpress:
    image: wordpress
    ports:
      - 8080:80

  mysql:
    image: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: examplepass

  varnish:
    image: eeacms/varnish
    ports:
    - "8000:6081"
    environment:
      DNS_ENABLED: "true"
      BACKENDS: "wordpress"
      BACKENDS_PORT: 8080

http 302是一个重定向,无论你运行的是什么,都能看到网址,但没有关注重定向,或者没有配置wordpress来提供正确的重定向。

更新:您看到的清漆错误是因为您正在探测/正在使用302重定向进行响应的wordpress服务器上。 Varnish似乎需要一个200成功代码来探测它的网址。为此,您可以将以下变量添加到清漆环境中:

BACKENDS_PROBE_URL: /wp-includes/js/jquery/jquery.js