Error response from daemon: Container ... is restarting, wait until the container is running and CMD directive?

Hello,

I am trying to create a docker image for a SMTP server based on CommuniGate Pro software.
I am using Docker version 19.03.15 on Debian 9.

I already succeeded to do that with that Dockerfile :

from debian:latest

ENV DEBIAN_FRONTEND noninteractive

COPY CGatePro-Linux_6.2-15_amd64.deb /root/
RUN dpkg -i /root/CGatePro-Linux_6.2-15_amd64.deb

ADD run.sh /root/run.sh
RUN chmod +x /root/run.sh
CMD ["/root/run.sh"]

My run.sh contains the start commands of CommuniGate Pro :

#!/bin/sh
set -e

APPLICATION="/opt/CommuniGate"
BASEFOLDER="/var/CommuniGate"
SUPPLPARAMS="--logToConsole"

[ -f ${APPLICATION}/CGServer ] || exit 1

# Custom startup parameters
if [ -f ${BASEFOLDER}/Startup.sh ]; then
  . ${BASEFOLDER}/Startup.sh
fi

echo "Starting CommuniGate Pro"

exec ${APPLICATION}/CGServer --Base ${BASEFOLDER} ${SUPPLPARAMS}

I start the container by :

$ docker run -d -v /var/CommuniGate-Back-node01:/var/CommuniGate \
		-m 1g \
		--network=cgpro-front-pp \
		--name=cgpro-back-node01-pp \
		--restart unless-stopped \
		-v /var/CommuniGate-SharedDomains:/var/CommuniGate/SharedDomains \
		-p 10021:10050 \
		--ip 172.18.0.21 \
		cgpro-back-node01-pp
$ docker ps
CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS                      NAMES
f50aac1980f8        gperrot:cgpro_6.2.15   "/root/run.sh"      5 seconds ago       Up 5 seconds        0.0.0.0:10021->10050/tcp   cgpro-back-node01-pp

The problem is that I want to stop the process /opt/CommuniGate/CGServer launched by /root/run.sh with docker exec -ti cgpro-back-node01-pp /etc/init.d/CommuniGate stop, it is automatically restarted and I don’t want that before doing certain operations.

So, I decide to not execute “/root/run.sh” in image by commenting CMD ["/root/run.sh"] or by replacing by CMD ["/bin/bash"] or CMD [“echo”, “Hello World”].
In all those cases, I can see the docker running but with a permanent restart state :

gperrot@cgpro-front-pp:~/cgpro$ docker ps
CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS                          PORTS               NAMES
df06011d0e04        gperrot:cgpro_6.2.15_nostart   "bash"              3 minutes ago       Restarting (0) 18 seconds ago                       cgpro-back-node01-pp

If I try to see what process are running by “docker exec -ti cgpro-back-node02-pp ps”
Error response from daemon: Container … is restarting, wait until the container is running

docker logs cgpro-back-node01-pp doesn’t give any output.

Any idea how to solve that problem ?

Thanks in advance for your help.

Gilper

The container does what it’s supposed to do, it executes whatever command was provided in CMD and ends the container. You need a foreground process to keep the container alive. Restarting the main process also kills the container (like you experienced with /etc/init.d/CommuniGate stop).

You should avoid manual changes inside the image, instead adapt the Dockerfile and/or entrypoint script to do whatever tweaks you want to apply - if it should be part of the image (=exist when the container is created) it belongs to the Dockerfile. If it’s instance individualization, it belongs in the entrypoint script.

Thanks a lot for your answer. What foreground process can I use in my case ? Could /bin/bash be used as a foreground process and if yes, how can I launched it ? If I put CMD ["/bin/bash"], it should execute /bin/bash in foreground since I didn’t put “&” at the end, no ?

Thanks in advance for your help.

Gilper

Just to be clear, your current CMD executes ["/root/run.sh"], which eventualy performs exec ${APPLICATION}/CGServer --Base ${BASEFOLDER} ${SUPPLPARAMS} to start the main process, which must be a foregroudn process as the container was kept running so far.

I am not sure how replacing the CMD with ["/bin/bash"] will help, as it will prevent your entrypoint script (and therefor your main application) to start. Like this, bash will not run as a foreground process and as a result the container will be immediatly terminated after executing the bash command, unless you start your container with docker run -ti -d (which is NOT a recommended solution, I would not even call it a workaround).

I would suggest to extend your entrypoint script to do whatever modifications you try to do manualy automaticly (like modifying config files based on the value of environment variables) before the exec CGServer command OR mount configuration folders/files from the host inside the container that make it unnessary to restart the server.

In order to have a good image, you will want to have the aspects automated that are required to individualize a container instance.

Thanks a lot for your answer. In fact, I need to stop and start manually the server since I want to test the upgrade of that server which needs manual intervention like withdrawing it from an application cluster by the GUI of the application . Any idea of the foreground process I could use with CMD ? You’re right, CMD ["/bin/bash"] doesn’t help.

Thanks in advance for your help.

Gilper.

Basicly you try to use the container like a vm, aren’t you?

But since you want to interact with the container, setting the CMD to ["/bin/bash"] and starting the container with docker run -ti ... should be just fine for your case.

Though to be honest, personaly I would use a vm instead a container for this use case (or at least a WSL2 distribution if you are on Windows).

Sorry, but I already start my container with -d :

docker run -d -v /var/CommuniGate-Back-node01:/var/CommuniGate \
		-m 1g \
		--name=cgpro-back-node01-pp \
		--restart unless-stopped \
		-v /var/CommuniGate-SharedDomains:/var/CommuniGate/SharedDomains \
                image

My Docker file is :

ADD run.sh /root/run.sh
RUN chmod +x /root/run.sh
CMD ["/bin/bash"]

But I still have a permanently restarting container :

CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS                          PORTS               NAMES
d7339bacd8db        gperrot:cgpro_6.2.15_nostart   "/bin/bash"         5 minutes ago       Restarting (0) 24 seconds ago                       cgpro-back-node01-pp

and I still can interact with the container :

docker exec -ti cgpro-back-node01-pp ps
Error response from daemon: Container ... is restarting, wait until the container is running

Any idea about the problem here ?

Thanks in advance for your help.

Giper

@meyay actually answered it

Check the documentation what -t and -i means. You can use them with -d too, altough it can sometimes stop your container when you run commands like docker attach.

On the other hand, there is an other command that you can use, since even if you run bash with an interactive terminal (-i: interactive, -t: TTY), you can’t simply and properly stop the container. It is not really a propbelm in your case since the container would stop eventually after 10 seconds, but here is the other way.

  1. Use sleep inf as command and
  2. Ask for an init process which handles stop signals properly if you use the --init flag.
CMD ["sleep", "inf"]
docker run -d --init ...

Or you can just

or use LXC containers instead of Docker containers if you are on Linux. I just wanted to note this, but if you can’t use these tools for some reason, then sleep inf will help.

Hello, Thanks a lot for your help. I try to launch “docker run -ti -d” and it solved my problem !

Have a good day !

Gilper