I am trying to create my own Nginx
image, using apline:latest
image, after fixing a lot of errors, thanks to the internet, I managed to do it and everything works fine, but the problem is when I run the following command :
rc-service nginx status
* status: stopped
and when I try to start the service this is what it gives me as shown below :
rc-service nginx start
* WARNING: nginx is already starting
even though the service is stopped the output of the second command tells it is already started?!
so I opened the localhost of my docker-machine to verify whether the service is on or off, and the nginx html page appears successfully.
I tried to run rc-service nginx reload
and this is the result:
rc-service nginx reload
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/blkio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpu/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpuacct/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/cpuset/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/devices/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/freezer/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/hugetlb/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/memory/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/net_cls/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/net_prio/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/perf_event/tasks: Read-only file system
/lib/rc/sh/openrc-run.sh: line 100: can't create /sys/fs/cgroup/pids/tasks: Read-only file system
* nginx: cannot `reload' as it has not been started
here is the output of nginx -t
:
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
and here is the output of less /var/log/nginx/error.log
as shown below there is no error :
less: can't open '/var/log/nginx/error.log': No such file or directory
this is my dockerfile :
From alpine:latest
COPY nginx.conf ./tmp
COPY index.html ./tmp
COPY run.bash ./tmp
COPY run2.bash ./tmp
RUN apk update &&
apk add nginx &&
adduser -D -g 'www' www &&
mkdir /www &&
chown -R www:www /var/lib/nginx &&
chown -R www:www /www &&
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig &&
apk add openrc --no-cache &&
sh tmp/run.bash
cmd sh tmp/run2.bash
run.bash :
mv tmp/nginx.conf /etc/nginx/nginx.conf
mv tmp/index.html /www/index.html
run2.bash :
mkdir /run/openrc
touch /run/openrc/softlevel
mkdir -p /run/nginx
nginx
sh
and this is the guide that I followed :
https://wiki.alpinelinux.org/wiki/Nginx
I want to know why rc-service nginx reload
doesn’t work even that my nginx service is running perfectly on my docker machine, and also why rc-service nginx status
tells that the nginx service is stopped even that it is not ?
and thanks in advance.
By the way when I run this command nginx -s reload
, it works without any errors.
2
Answers
After debugging and lots of trial and error, I found a perfect solution at least for me, David Maze answer is very helpful, but for testing purpose I need my shell to be accessible, because when u run
nginx -g "daemon off;"
you can't access your container shell unless you stop the command process.whatever when I start my container using the following command :
we access the container shell, and we need to download
nginx
server , andopenrc
to be able to userc-service
command line.#ANSWER 1
now we'll test If there is an error in nginx server by using the following command :
as you can see from the output that we get, It tells you that a missing file or directory shall be created, so let's create that directory :
and we give that directory that we created some permissions :
now we are good with nginx :
Let's test our nginx service is it started or not with
rc-service
command :So from the above output we see that we have two problems,
openrc
did not boot, and there is a missing filesoftlevel
:Let's start by booting our system with
openrc
simply by typing it itself :now we create the missing file :
now our
rc-service
command works perfectly :let's start our server :
check if it is started or not :
#ANSWER 2
Or you can simply call those two command lines instead :
Now you can start your nginx server :)
Hope I was clear.
A Docker container generally only runs a single process. You don’t need to "start a service" or "restart a service"; generally the server process itself is the main container process, and if you need to restart the service, you restart the entire container. Often "service"-type commands are missing some key piece of infrastructure in a Docker context and just won’t work.
In your Dockerfile, you can just make the main command be to launch Nginx as a foreground process
and then when you need to change the configuration, build a new image and recreate the container