Docker公开服务以实现Docker化的wordpress多站点

时间:2018-12-13 17:23:02

标签: wordpress docker docker-compose

我一直在尝试为dockerized的Wordpress应用程序启用Wordpress多站点网络。 可以通过IP和端口访问该应用程序,如下所示:

http://0.0.0.0:8282

当我在WP_ALLOW_MULTISITE中启用wp-config.php时,我收到了来自Wordpress的错误消息,即我无法将域名用于端口,例如:8282 在这种情况下。

所以我一直在寻找一种方法,该方法如何从Docker容器而不是0.0.0.0:8282公开一些域名

我找到了这个例子:

https://www.theimpossiblecode.com/blog/docker-wordpress-multisite-with-subdomains/

正如所描述的,我仔细研究了该示例以使其起作用。然后,我打算寻找一种方法来为我的特定应用程序实现它。

问题:

我首先公开了服务,如链接页面所述:

https://www.theimpossiblecode.com/blog/docker-expose-service/

在运行该页面时,我使用了随附的docker-compose.yml

$ docker-compose up -d

容器似乎正在工作:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
edaeb215b3eb        wordpress:latest    "docker-entrypoint.s…"   34 minutes ago      Up 34 minutes       80/tcp                dockwpress_wordpress_1
5dc6fa8480c6        mysql:5.7           "docker-entrypoint.s…"   34 minutes ago      Up 34 minutes       3306/tcp, 33060/tcp   dockwpress_db_1

但是,我无法访问:http://dockerwp$ dig dockerwp会产生以下结果:

; <<>> DiG 9.10.6 <<>> dockerwp
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 23290
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;dockerwp.          IN  A

;; Query time: 34 msec
;; SERVER: 10.11.137.100#53(10.11.137.100)
;; WHEN: Thu Dec 13 17:05:34 GMT 2018
;; MSG SIZE  rcvd: 37

检查容器时,我发现dockerwp域名已经公开(“ com.theimpossiblecode.expose.host”:“ dockerwp”行)。

$ docker inspect edaeb215b3eb


[
    {
        "Id": "edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb",
        "Created": "2018-12-13T16:28:55.122420503Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "apache2-foreground"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 10823,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2018-12-13T16:28:55.733061919Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:55b751a7663f6d4fdd0d5f3785b0a846868147dceff99dd169f0a33214be3452",
        "ResolvConfPath": "/var/lib/docker/containers/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb/hostname",
        "HostsPath": "/var/lib/docker/containers/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb/hosts",
        "LogPath": "/var/lib/docker/containers/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb/edaeb215b3eb37e681fed81099c2de65425a4a6c735529366112ba5436e937cb-json.log",
        "Name": "/dockwpress_wordpress_1",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "dockwpress_default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [],
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "shareable",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/asound",
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/8ab6c3eb7bb9e80de85a5c39849775d339d9466c182b236eca411f1cb32d7f29-init/diff:/var/lib/docker/overlay2/44b78d4977abf7cab796267c277db0e31efd5190f917dce4167237070fb0317e/diff:/var/lib/docker/overlay2/1d3fb40ede0d5e2626d4d1ea19e93cb15702a7bcb569bf2811e652d25409623f/diff:/var/lib/docker/overlay2/f59d3c961f65e7ad1297bf888ed04905dff998a31a5796c7c903a8f854749a3b/diff:/var/lib/docker/overlay2/af222f8ba1e9c68b16935d08a0325ec8ff173a2944082e8d3e568a2c738d591f/diff:/var/lib/docker/overlay2/1bac18c6dc58c3ebd7982dd3ccdfb7fdbc4037de6277c20d84baba95babaf4c1/diff:/var/lib/docker/overlay2/32df749d5027d957ebba6167f8715bbbc117c0787c8d5849f318391d427dfcaf/diff:/var/lib/docker/overlay2/e6927c13204369a44dc8f4de4a8ab8a3307b0f8fa5eb758a565a67a1b923451a/diff:/var/lib/docker/overlay2/a6299eec8f02b0c2a190a9646b7576209e0e39f6bae1d81f543daaabe0dd89d4/diff:/var/lib/docker/overlay2/d0e4d7ff78e7373c4f3885e8cad840617764e9a803bda6eb30e681cdc910bf51/diff:/var/lib/docker/overlay2/fc48c85e773fd6d0e52b4a84116224d2ee0a396a470df44b009fb56ef8276704/diff:/var/lib/docker/overlay2/77aea6e322140a30aff363c97e67bad3f2ab78f301ebdadc89275f9e1e86ad0d/diff:/var/lib/docker/overlay2/fec4aae10fb644332df8a1c286c9635a1ae85f2d9aaf8838ae08b7e6f3268a8d/diff:/var/lib/docker/overlay2/41bfdb4f1afa0d88890af4deb33c403e5816a6b2823d3a9ed5fb19079b4faa9b/diff:/var/lib/docker/overlay2/5aa746815fbdaeedc7a727ca34072f1183af9bc0ba7908b480e37ee9f5884761/diff:/var/lib/docker/overlay2/aa6c25c7e61f3512a55f69ed5c39f492b80a500704bdc9a91af8ff811f74f58d/diff:/var/lib/docker/overlay2/41c27f1bb64072e7deebc7eee4b46f3c38b63e2bc56ebfaf9c88159f1d6c67c2/diff:/var/lib/docker/overlay2/512ece5edecc822e72e5d939d75339e02582696dbc5205f756516c4b635ff9d3/diff:/var/lib/docker/overlay2/7bd7bb38c22c9ee4dd2c38d2c32ac12bbb2034c759879a26b73b351ac7a5e26e/diff:/var/lib/docker/overlay2/602c7d2fa85ca8e4945236214ffb852abcfd716f5626d273b510b470d7878d02/diff",
                "MergedDir": "/var/lib/docker/overlay2/8ab6c3eb7bb9e80de85a5c39849775d339d9466c182b236eca411f1cb32d7f29/merged",
                "UpperDir": "/var/lib/docker/overlay2/8ab6c3eb7bb9e80de85a5c39849775d339d9466c182b236eca411f1cb32d7f29/diff",
                "WorkDir": "/var/lib/docker/overlay2/8ab6c3eb7bb9e80de85a5c39849775d339d9466c182b236eca411f1cb32d7f29/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "bd2706aae2dbddaa65a85e77ca89efc3844dc600f72e1e8b1f9b6803cbb8459c",
                "Source": "/var/lib/docker/volumes/bd2706aae2dbddaa65a85e77ca89efc3844dc600f72e1e8b1f9b6803cbb8459c/_data",
                "Destination": "/var/www/html",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "edaeb215b3eb",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "WORDPRESS_DB_HOST=db:3306",
                "WORDPRESS_DB_USER=wordpress",
                "WORDPRESS_DB_PASSWORD=wordpress",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "PHPIZE_DEPS=autoconf \t\tdpkg-dev \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c",
                "PHP_INI_DIR=/usr/local/etc/php",
                "APACHE_CONFDIR=/etc/apache2",
                "APACHE_ENVVARS=/etc/apache2/envvars",
                "PHP_EXTRA_BUILD_DEPS=apache2-dev",
                "PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2 --disable-cgi",
                "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2",
                "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2",
                "PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie",
                "GPG_KEYS=1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F",
                "PHP_VERSION=7.2.13",
                "PHP_URL=https://secure.php.net/get/php-7.2.13.tar.xz/from/this/mirror",
                "PHP_ASC_URL=https://secure.php.net/get/php-7.2.13.tar.xz.asc/from/this/mirror",
                "PHP_SHA256=14b0429abdb46b65c843e5882c9a8c46b31dfbf279c747293b8ab950c2644a4b",
                "PHP_MD5=",
                "WORDPRESS_VERSION=5.0",
                "WORDPRESS_SHA1=67758958f14c1dcefe37ce6558d470a4e142893b"
            ],
            "Cmd": [
                "apache2-foreground"
            ],
            "ArgsEscaped": true,
            "Image": "wordpress:latest",
            "Volumes": {
                "/var/www/html": {}
            },
            "WorkingDir": "/var/www/html",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "c8ce0ffef4cef318c23c0e6142dcb5b42a97df29507969c72a99e95b3343f0ec",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "dockwpress",
                "com.docker.compose.service": "wordpress",
                "com.docker.compose.version": "1.23.2",
                "com.theimpossiblecode.expose.host": "dockerwp"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "83bdba7bf688685fa842ab8c1c38a53f26af088c2fd1063492ae55cb73cc6cd6",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/83bdba7bf688",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "dockwpress_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "wordpress",
                        "edaeb215b3eb"
                    ],
                    "NetworkID": "6b7d8cc32a6e208f379a8ecfdf88910c85c575e284ad2e3632520fe86ec937ad",
                    "EndpointID": "a7d991d525463bb83b2eedb78baf59358d8a543f3b5244034eaea6cce99ef525",
                    "Gateway": "172.28.0.1",
                    "IPAddress": "172.28.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:1c:00:03",
                    "DriverOpts": null
                }
            }
        }
    }

]

是什么导致无法访问http://dockerwp

浏览器显示此错误:

This site can’t be reached dockerwp’s server IP address could not be found.
Did you mean http://docker.com/?
Search Google for docker wp
ERR_NAME_NOT_RESOLVED

谢谢。

2 个答案:

答案 0 :(得分:1)

http://dockerwp中的

dockerwp是不存在的域名。

仅当您将wp站点部署到他们的平台(这将为您提供一个名为“ dockerwp”的子域)时,您的示例才有效。标签om.theimpossiblecode.expose.host由其反向代理读取以创建此效果。

最后,您不能使用此配置设置主机名。最好只使用localhost:port访问您的站点。

答案 1 :(得分:0)

解决方案是使用Nginx代理服务器,例如https://github.com/jwilder/nginx-proxy

因此,通过使用两个容器,一个是代理,另一个是Wordpress应用程序docker容器,您可以将/etc/hosts的虚拟主机条目添加到127.0.0.1 devwebsite.local中,以用于任何所需的虚拟主机。必须为WP容器VIRTUAL_HOST env配置它们。变量。

以下是示例:https://github.com/djuro/dockerMultisiteWordpress,特别是Dockerfile和docker-compose.yml。

我又使用了2个容器,分别用于数据库和GUI db工具(管理员),但这两个容器都是可选的。