Home > database >  ERROR: cannot start nginx as networking would not start on alpine docker image
ERROR: cannot start nginx as networking would not start on alpine docker image

Time:09-22

We are trying to install and run nginx on java based alpine image (anapsix/alpine-java:7_jdk) but we are facing below error when we start it

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

We have tried many articles but nowhere it is mentioned that how to fix networking issue with the nginx on this alpine based image. Even if we create /etc/network/interfaces file, we don't know what should be the correct values inside it. Below is what we are running 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

Please help us to achieve this.

CodePudding user response:

I managed to get Nginx to work within anapsix/alpine-java:7_jdk image after seeing this amazing answer.

Here is a working 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

and here is the script.bash used in CMD :

#!/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

after building the image using docker build . -t nginx_alpine_java run the following commands :

docker run -it -p 80:80 nginx_alpine_java

now we are inside our container 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 ]

I hope that it will work with you.

  • Related