Starting a service during Docker build

I would like to start the service during the build of Docker. I do not need this service to continue working after the build process is complete (or I know that I can use the CMD command for this), but I need it to work long enough to execute the second command, which relies on this service and works.

To be more precise, I am trying to write a Docker file for the ejabberd XMPP server, which also installs a module for this server. I am trying to start an ejabberd server with running ejabberdctl, and then install the module using the ejabberdctl module_install utility, which depends on starting and starting node. It looks like this:

RUN ejabberdctl start && ejabberdctl modules_update_specs && ejabberdctl module_install ejabberd_auth_http

Now I had a problem, and I came up with two possible reasons. The problem is that my assembly does not work from this line, because node does not work when the second command tries to execute. I get the following error, which is typical when you try to use the ejabberdctl utility, without node actually up:

RPC connection failed with node ejabberd @localhost

The command '/ bin / sh -c ejabberdctl start && & & & ejabberdctl modules_update_specs && & & ejabberdctl module_install ejabberd_auth_http' returned a non-zero code: 3

, , , node, . , . , , init.d, Docker .

, , , .

, , ejabberd , . , ejabberdctl.

+4
1

*ctl // .

, , , bash script, , :

  • start ejabberd
  • ,

:

root@158479dec020:/# ejabberdctl status
Failed RPC connection to the node ejabberd@158479dec020: nodedown
root@158479dec020:/# echo $?
3
root@158479dec020:/# ejabberdctl start 
root@158479dec020:/# echo $?
0
root@158479dec020:/# ejabberdctl status
The node ejabberd@158479dec020 is started with status: started
ejabberd 16.01 is running in that node
root@158479dec020:/# echo $?
0
root@158479dec020:/# ejabberdctl stop  
root@158479dec020:/# echo $?
0
root@158479dec020:/# ejabberdctl status
Failed RPC connection to the node ejabberd@158479dec020: nodedown
root@158479dec020:/# echo $?
3

, , ejabberd status, , 3, 0, .

bash script:

function run() {
  ejabberdctl start # Repeating just in case...
  ejabberdctl status &>/dev/null

  if [ $? -eq 0 ]; then
    echo "Do some magic here, ejabberd is running..."
    exit 0
  fi 

  echo "Ejabberd still down..."
}

while true; do run; sleep 1; done

, CLI:

root@158479dec020:/# ./check.sh 
Ejabberd still down...
Do some magic here, ejabberd is running...
root@158479dec020:/# ejabberdctl stop
root@158479dec020:/# ./check.sh 
Ejabberd still down...
Ejabberd still down...
Do some magic here, ejabberd is running...
0

Source: https://habr.com/ru/post/1674745/


All Articles