阿帕奇在alpine镜像的Docker中无法启动

4

Apache在alpine docker镜像中无法启动。以下是我的docker文件

 FROM alpine:latest
 RUN apk update
 RUN apk upgrade
 RUN apk add bash
 RUN apk add apache2
 RUN apk add openrc
 RUN rc-update add apache2
 EXPOSE 80 443
 WORKDIR /var/www/localhost/htdocs
 COPY  index.html  /var/www/localhost/htdocs 

我尝试在登录到正在运行的docker后手动启动Apache,但不起作用

错误信息为:

 * You are attempting to run an openrc service on a
 * system which openrc did not boot.
 * You may be inside a chroot or you may have used
 * another initialization system to boot this system.
 * In this situation, you will get unpredictable results!
 * If you really want to do this, issue the following command:
 * touch /run/openrc/softlevel
 * ERROR: networking failed to start
 * ERROR: cannot start apache2 as networking would not start

你可以尝试使用这个 Docker Hub 镜像 - juanlumn
@juanlumn 谢谢,这个可以正常工作了。我还在官方 Docker Hub 上找到了 alpine 版本的 apache,它是 httpd:2.4.37-alpine - sandy
2个回答

8
试试这个:
FROM alpine:latest
RUN \
    apk add --no-cache \
    apache2-proxy \
    apache2-ssl \
    apache2-utils \
    curl \
    git \
    logrotate \
    openssl

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

WORKDIR /var/www/localhost/htdocs
COPY  index.html  /var/www/localhost/htdocs 

EXPOSE 80

CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]

是的,我正在处理。看起来二进制路径是 /usr/sbin/httpd。 - sandy
1
容器正在启动,但很快就会退出。 - sandy
1
是的,抱歉在Alpine上它是/usr/sbin/httpd。我尝试运行了,你的错误信息是什么?我得到了“httpd:无法可靠地确定服务器的完全限定域名,使用172.17.0.2。设置'ServerName'指令全局以抑制此消息”。 - Nima Hashemi
我看到了这个警告,当我在容器内手动运行命令时,Apache正在运行,但从未尝试连接80端口。bash-4.4#telnet localhost 80 telnet:无法连接到远程主机(127.0.0.1):连接被拒绝 - sandy

7

我曾经面临同样的问题,你可以不使用openrc来启动apache。

RUN mkdir -p /run/apache2添加到您的Dockerfile中,Apache将在此目录中存储httpd.pid文件。最后使用以下命令启动Apache:exec /usr/sbin/httpd -D FOREGROUND


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接