Docker.io init.d script does not work in launch container

I have a container with odoo on it in the directory "/ opt / odoo /".

A init script on "/etc/init.d/odoo-server"

#!/bin/bash ### BEGIN INIT INFO # Provides: odoo # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start openerp daemon at boot time # Description: Enable service provided by daemon. # X-Interactive: true ### END INIT INFO ## more info: http://wiki.debian.org/LSBInitScripts PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin DAEMON=/opt/odoo/openerp-server NAME=odoo DESC=odoo CONFIG=/etc/odoo-server.conf LOGFILE=/var/log/odoo/odoo-server.log PIDFILE=/var/run/${NAME}.pid USER=odoo export LOGNAME=$USER test -x $DAEMON || exit 0 set -e function _start() { start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $DAEMON -- --config $CONFIG --logfile $LOGFILE } function _stop() { start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo --retry 3 rm -f $PIDFILE } function _status() { start-stop-daemon --status --quiet --pidfile $PIDFILE return $? } case "$1" in start) echo -n "Starting $DESC: " _start echo "ok" ;; stop) echo -n "Stopping $DESC: " _stop echo "ok" ;; restart|force-reload) echo -n "Restarting $DESC: " _stop sleep 1 _start echo "ok" ;; status) echo -n "Status of $DESC: " _status && echo "running" || echo "stopped" ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 exit 1 ;; esac exit 0 

then i do

 root@cca438c81a87:/# update-rc.d odoo-server defaults Adding system startup for /etc/init.d/odoo-server ... /etc/rc0.d/K20odoo-server -> ../init.d/odoo-server /etc/rc1.d/K20odoo-server -> ../init.d/odoo-server /etc/rc6.d/K20odoo-server -> ../init.d/odoo-server /etc/rc2.d/S20odoo-server -> ../init.d/odoo-server /etc/rc3.d/S20odoo-server -> ../init.d/odoo-server /etc/rc4.d/S20odoo-server -> ../init.d/odoo-server /etc/rc5.d/S20odoo-server -> ../init.d/odoo-server 

When I start docker with docker running, the odoo server does not start, when I run inside docker / etc / init.d / odoo-server, it works fine ...

what's happening?

+8
docker ubuntu openerp odoo
source share
5 answers

Dock containers generally do not have a functioning initialization system. If you just start one service, just start it.

If you need something more complex, check out supervisord or runit .

Containers are not virtual machines.

+12
source share

If you're looking for a Docker image that behaves like a full-blown init virtual machine, check out phusion baseimage

+4
source share

Now I found an error within a few hours of operation.

The reason for the problem is that start-stop-daemon , the main tool for starting the starter / tester / plug of the Debian system, checks for the existence of the daemon by examining the virtual software connection of the daemon process in /proc/<pid>/exe (it should point to process binary image).

Now the problem is that in docker this program link simply will not work by default. This is due to the fact that the docker must use strict security policies during installation by default (it is mainly used to run unidentified software).

There are many workarounds for the task, some of which should change the privilege settings of the container, and some should not. Two examples:

  • You modify the init scripts so that you do not use start-stop-daemon with the --test and --exec
  • You launch your docker run containers by providing --cap-add=SYS_ADMIN options to the docker run (don't worry, it does not give your docker run containers any sysadm privileges, this is probably just a precaution for productive use)

Next to them, also, systemd does not work in docker, although this is probably more of a disadvantage of system d, since docker. Instead of systemd upstart can be used.


Ps: docker developers / supporters often say "containers are not virtual machines" and the like. But, in everyday experience, there is not such a really strong difference between the two, and for the productive use of dockers in software, at least minimal support for a function like VPS would undoubtedly be useful. I hope that the development of dockers will be concentrated in this direction in the near future.

+3
source share

I found that the service does not start because /usr/sbin/policy-rc.d returns code 101:

See: http://jpetazzo.imtqy.com/2013/10/06/policy-rc-d-do-not-start-services-automatically/

And the docker installed it to return to the container.

So, change that the script on the assembly will work, you can make build.sh to run in the Dockerfile and run the script below:

 cat << EOF > /usr/sbin/policy-rc.d #!/bin/sh # For most Docker users, "apt-get install" only happens during "docker build", # where starting services doesn't work and often fails in humorous ways. This # prevents those failures by stopping the services from attempting to start. # exit 101 exit 0 EOF 
+1
source share

It looks like your shebang is wrong, instead of #! / Bin / bash it should be #! / Ben / w

See: https://unix.stackexchange.com/questions/124566/how-to-debug-init-d-script-that-isnt-being-run

-4
source share

All Articles