docker - 错误 : cannot start nginx as networking would not start on alpine docker image

标签 docker nginx dockerfile nginx-reverse-proxy alpine-linux

我们正在尝试在基于 java 的 alpine 镜像 (anapsix/alpine-java:7_jdk) 上安装和运行 nginx,但是当我们启动它时遇到以下错误

rc-service nginx start
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/blkio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/cpu/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/cpu,cpuacct/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/cpuacct/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/cpuset/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/devices/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/freezer/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/hugetlb/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/memory/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/net_cls/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/net_cls,net_prio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/net_prio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/perf_event/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/pids/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 250: can't create /sys/fs/cgroup/systemd/tasks: Read-only file system
 * Starting networking ...
awk: /etc/network/interfaces: No such file or directory
 * ERROR: networking failed to start
 * ERROR: cannot start nginx as networking would not start

我们试过很多文章,但没有提到如何解决这个基于 alpine 的图像上的 nginx 网络问题。即使我们创建了 /etc/network/interfaces 文件,我们也不知道里面的正确值应该是什么。下面是我们正在运行的 Dockerfile

# Add Nginx
RUN apk --update add nginx openrc
RUN mkdir -p /run/nginx
RUN touch /run/nginx/nginx.pid
# RUN adduser -D -g 'nginx' nginx
# RUN mkdir /home/nginx
RUN chown -R nginx:nginx /var/lib/nginx
# RUN chown -R nginx:nginx /home/nginx
COPY birt.conf /etc/nginx/conf.d/birt.conf
# COPY index.html /nginx
RUN openrc
RUN touch /run/openrc/softlevel
RUN rc-update add nginx default

请帮助我们实现这一目标。

最佳答案

在看到这个惊人的 answer 图像后,我设法让 Nginx 在 anapsix/alpine-java:7_jdk 图像中工作.

这是一个有效的 Dockerfile :

FROM anapsix/alpine-java:7_jdk

COPY script.bash .

RUN apk --update add nginx openrc
RUN openrc
RUN touch /run/openrc/softlevel

CMD bash ./script.bash

这是 CMD 中使用的 script.bash :

#!/bin/bash

# Tell openrc loopback and net are already there, since docker handles the networking
echo 'rc_provide="loopback net"' >> /etc/rc.conf

# get inside the container bash
bash

在使用 docker build 构建图像之后。 -t nginx_alpine_java 运行以下命令:

docker run -it -p 80:80 nginx_alpine_java

现在我们在容器 bash 中

bash-4.3# rc-service nginx status
 * status: stopped

bash-4.3# rc-service nginx start
 * /run/nginx: creating directory
 * /run/nginx: correcting owner                                [ ok ]
 * Starting nginx ...                                          [ ok ]

希望对你有用。

关于docker - 错误 : cannot start nginx as networking would not start on alpine docker image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69218786/

相关文章:

logging - Nginx - 从记录到 access.log 中排除特定文件或文件夹

mysql - 在 docker-compose 中执行 mysql 命令时出错

bash - 在 unix :///var/run/docker. sock 处对 Docker 守护程序套接字的权限被拒绝

来自 IFSC 代码的 Azure Devops Docker 镜像没有这样的文件或目录

nginx - docker中nginx的动态default.conf

google-app-engine - Google Cloud Shell,从1.9.1升级Docker,这不可能吗?

docker - 带有Docker的动态Nginx代理

docker - Flask 上的 80 端口显示 "Welcome to nginx"

docker : where are files downloaded? 上的 RSelenium

python - 在docker容器中启动mysql后插入数据