遵循docker教程,但教程和实际输出不同
我是docker的新手,试图了解这个领域是什么。我无意中发现了以下几点。我是一名后端开发人员,喜欢这个教程,因为它讨论了微服务,但教程没有解释命令。例如,我目前被困在 我按照命令运行遵循docker教程,但教程和实际输出不同,docker,Docker,我是docker的新手,试图了解这个领域是什么。我无意中发现了以下几点。我是一名后端开发人员,喜欢这个教程,因为它讨论了微服务,但教程没有解释命令。例如,我目前被困在 我按照命令运行 docker run -p 80:80 --name my-apache2-alpine-1 my-apache2-alpine 这是这个命令在我的终端上的输出 $ docker run -p 80:80 --name my-apache2-alpine-1 my-apache2-alpine [s6-ini
docker run -p 80:80 --name my-apache2-alpine-1 my-apache2-alpine
这是这个命令在我的终端上的输出
$ docker run -p 80:80 --name my-apache2-alpine-1 my-apache2-alpine
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 30-resolver: executing...
[cont-init.d] 30-resolver: exited 0.
[cont-init.d] 40-resolver: executing...
[cont-init.d] 40-resolver: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] syncing disks.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.
该命令没有产生教程中指出的预期结果,即,http://localhost:80/myindex.html
为“无法连接”,即服务器未在那里运行
下面是我的问题
更新 以下是
Dockerfile
~/docker-practice/static-site$ cat Dockerfile
FROM smebberson/alpine-apache
ADD ./public-html/myindex.html /var/www/localhost/htdocs
~/docker-practice/static-site$
我在这里缺少什么,为什么我并没有得到教程中指出的预期结果
首先,我认为你在遵循一个糟糕的教程。首先,我将从可用的文档和示例开始。但是,我们可以诊断问题
看起来Apache正在失败,因为您的容器在启动Apache后立即退出。当Apache失败时,它会将消息写入Apache配置中通过ErrorLog
指令配置的路径。我们首先需要找出该文件的位置,然后在尝试启动Apache之后需要进行检查
让我们从图像生成一个shell开始,绕过默认行为:
docker run -it --rm --entrypoint sh my-apache2-alpine
这会给你一个贝壳。尝试手动启动Apache:
/ # httpd -DFOREGROUND
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
/ #
现在,让我们看看Apache在哪里编写错误日志。我们可以使用apachectl-S
命令:
/ # apachectl -S
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
ServerRoot: "/var/www"
Main DocumentRoot: "/var/www/localhost/htdocs"
Main ErrorLog: "/var/www/logs/error.log"
Mutex default: dir="/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
PidFile: "/run/apache2/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=1000
Group: name="apache" id=1000
/ #
从上面的输出中,我们看到主要的错误日志是/var/www/logs/error.log
。如果我们查看该文件,我们会看到:
/ # cat /var/www/logs/error.log
[Wed Nov 20 01:22:25.012196 2019] [core:error] [pid 41] (2)No such file or directory: AH00099: could not create /run/apache2/httpd.pid
[Wed Nov 20 01:22:25.012226 2019] [core:error] [pid 41] AH00100: httpd: could not log pid to file /run/apache2/httpd.pid
/ #
现在我们知道了Apache为什么不启动了:它想将一个PID文件写入/run/apache2/httpd.PID
,但是没有/run/apache2
目录。有几种方法可以解决这个问题:
FROM smebberson/alpine-apache
RUN mkdir -p /run/apache2
ADD ./public-html/myindex.html /var/www/localhost/htdocs
--tmpfs
命令行选项创建目录:
docker run -p 80:80 --name my-apache2-alpine-1 --tmpfs /run/apache2 my-apache2-alpine
docker run -p 80:80 --name my-apache2-alpine-1 my-apache2-alpine
这将从
my-apache2-alpine
图像创建一个新容器(docker run
)。它将名称my-apache2-alpine-1
分配给容器(--name my-apache2-alpine-1
),因此您可以使用该名称来管理该容器,而不是容器id。最后,它在主机端口80(-p 80:80
)上发布容器端口80,这样,您就可以像直接在主机上运行一样访问web服务器。最后一个问题是离题的,仅供参考。要求查找指南/教程是投票结果接近的原因之一:(我已经删除了最后一个问题。你能在你的问题中包含docker文件的实际文本吗?看起来你运行的是某种有点不寻常的初始化系统。我已经在我的问题中添加了docker文件的内容。谢谢。这真的是一个很好的解释。感谢链接到docker教程。与那篇教程从一开始就包括了库伯内特。作为一个连docker都不懂的人,添加库伯内特只会让我感到困惑