我正在尝试将我的 wordpress 博客从主机转移到我自己的服务器。我想使用 docker 来完成这项任务。
在我的服务器上运行 nginx,它承载了许多与这个问题无关的服务。我使用以下脚本来创建一个容器。
#!/bin/bash
docker create --name blog \
--net bridge \
-e WORDPRESS_DB_HOST=192.168.170.11 \
-e WORDPRESS_DB_USER=USER \
-e WORDPRESS_DB_PASSWORD=PASSWORD \
-e WORDPRESS_DB_NAME=wordpress \
-v /var/www/wordpress:/var/www/html \
-p 8000:80 \
wordpress
Run Code Online (Sandbox Code Playgroud)
数据库连接有效并且 apache2 正在运行。但是我无法访问wordpress。
当我尝试访问时localhost:8000,将我重定向到80nginx 正在侦听的端口。为什么?我想连接到容器内的端口 80 (apache2)。
当我从外部尝试此操作时也是如此(如果防火墙关闭)。
另一个问题是防火墙:端口 8000/tcp 对所有 IP 都是开放的,但我来自外部的请求仍然被阻止。我必须为这个 docker 容器打开什么?
运行Docker version 17.05.0-ce, build 89658be上Debian Stretch。
编辑:
root@server:~/docker# curl -v http://localhost:8000
* Rebuilt URL to: http://localhost:8000/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8000 (#0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Mon, 12 Feb 2018 20:08:48 GMT
< Server: Apache/2.4.25 (Debian)
< X-Powered-By: PHP/7.2.1
< Set-Cookie: PHPSESSID=b03c4c1ba164bef366c49e1b1b5abc1c; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
< Set-Cookie: PHPSESSID=7293f22e5c860504a429b070d0ad21e4; path=/
< Location: http://localhost/
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
<
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
Run Code Online (Sandbox Code Playgroud)
我没有胶水在这里转发我。Apache2 在 docker 中。没有 .htaccess 文件,我没有修改图像。
暂时停止您的 nginx,使用docker run -p 80:80 [...]. 然后你的浏览器就可以访问 http://localhost/wp-admin/; 应该有一个名为“站点 URL”之类的属性。将其更改为http://localhost:8000/并保存。
这将导致 Wordpress 重定向(它将使用 HTTP 301)任何访问者,以http://localhost:8000/了解 Apache 是否正在侦听该端口。
然后docker commit您的自定义,并运行提交的图像 docker run -p 8000:80 [...]
| 归档时间: |
|
| 查看次数: |
9101 次 |
| 最近记录: |