Home > Enterprise >  Docker CMD exit 0
Docker CMD exit 0

Time:01-13

I'm trying to make a container that on start runs a maven command if a folder do not exists; but always after run the command I get a message "Neomind_dev exited with code 0".

Is there a way by dockerfile or docker-compose to run a script with return after the container start and do not let the container exit?

the dockerfile:

FROM tomcat
ENV MAVEN_VERSION "3.8.4"
ENV MAVEN_HOME "/usr/share/maven"
ENV PATH "${MAVEN_HOME}/bin:${PATH}"

# Install tools
RUN apt-get update && \
    wget -O /tmp/apache-maven-${MAVEN_VERSION}.zip http://ftp.unicamp.br/pub/apache/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.zip && \
    unzip /tmp/apache-maven-${MAVEN_VERSION}.zip -d /usr/share && \
    mv /usr/share/apache-maven-${MAVEN_VERSION} ${MAVEN_HOME} && \
    rm -rf /tmp

COPY settings.xml ${MAVEN_HOME}/conf/settings.xml
COPY ./build.sh /

WORKDIR /
CMD sh build.sh

the script

if [ ! "$(ls /usr/local/fusion)" ]; then 
cd /usr/local 
mvn archetype:generate -B -Pneomind-archetype -DarchetypeGroupId=com.neomind.archetype -DarchetypeArtifactId=fusion-client-archetype -DarchetypeVersion=1.1 -DtenantId=Neomind-dev -DfusionVersion=3.15.5 
fi

CodePudding user response:

  1. Container exits because your scripts run without error and ends the process.
  2. To keep the process/container running you can add a command at last of docker file for tomcat to be running continuously : CMD ["catalina.sh" "run"].
  •  Tags:  
  • Related