docker container : service exits immediately

I run a container in the background

docker run -d -e SERVER_ADDR= --name resource agent:1.0

but it exited immediately.


FROM centos:latest
MAINTAINER Simon <[email protected]>

RUN yum -y update; yum clean all
RUN yum -y install systemd; yum clean all;

RUN mkdir -p /cloud/config
RUN mkdir -p /cloud/log

WORKDIR /cloud

COPY sm_agent_resource sm_agent_resource
COPY config/agent.conf config/agent.conf
COPY config/log.xml config/log.xml
COPY cloud-resource cloud-resource
COPY certificate.pem certificate.pem
COPY client.crt client.crt
COPY client.key client.key

CMD /cloud/cloud-resource


# chkconfig: 234 90 90


echo "Agent Config Setting"
sed -i '3i  "agent_server_ip":"'${SERVER_ADDR}'",' config/agent.conf

echo "Start Cloud Agent_Resource"
nohup /cloud/sm_agent_resource 1>/dev/null 2>&1 &
#nohup /cloud/sm_agent_resource >>log/agent.log 2>&1 (<==I try it also.)

When I connected to the docker by /bin/bash and run the cloud-resource, process was running.

run -d -it -e SERVER_ADDR= --name resource1 agent:1.0 --entrypoint /bin/bash 

Source: StackOverflow