Docker Community Forums

Share and learn in the Docker community.

Docker Container stopped automatically after starting

docker
dockerhub

(babs84) #1

I have an issue with the Docker container where the container stopped automatically after starting. I am not able to figure out what is the issue.

Here is my simple DockerFile where i am pulling the tomcat image and deploying my war file to the /usr/local/tomcat/webapps folder
FROM tomcat

RUN apt-get update && apt-get -y upgrade

WORKDIR /usr/local/tomcat

ADD app.war /usr/local/tomcat/webapps/app.war

EXPOSE 8091

I am using the following command to start the container
docker run -p 8091:8091 -d containerName

After running the above command, i can see that tomcat server is starting. When it started completely, the container stopped automatically.
I have tried using different commands like below, but didn’t help.
docker run -p 8091:8091 -itd containerName

Am i using wrong parameters to run the container ? Should i need to update the dockerfile ? Any information would help me in solving this issue.


(8hanman8) #2

try this: docker run -it -p 8091:8091 containerName


(babs84) #3

I got it working after changing the COPY command instead of ADD command in my Dockerfile


(Axpraka) #4

Not sure how that fixed the code.

Include ENTRYPOINT command which runs in background.

You can check exit code of container if it is 0 means container exited after all exection, means you have to run the process in foreground to keep container running.

if exit code is other than 0, means it is exiting because of code issue.


(David Maze) #5

ADD automatically unpacks archives of types it recognizes; COPY directly copies files over. (See the Dockerfile ADD docs.) Since Java .war archives are secretly zip files (containing Java .jar files, which are also zip files) Docker will helpfully unpack them for you.

In practice, you usually want COPY unless you’re sure you want to unpack a tar or zip file.

If you did something like

docker run --rm -it myimage /bin/sh

you’d (probably) get an interactive shell where you could verify that the file layout is what you expected.


(babs84) #6

What you said is actually correct. I had an issue of tomcat server did not get started correctly, using the COPY command instead of ADD fixed that issue. But to make the container running i had to do one more step of including the ENTRYPOINT as like below

ENTRYPOINT ["/docker-entrypoint.sh"]

After that, i am able to make the container stay alive.

I did not complete my answer in the first place.


(Meemicaudi) #7

One thing that can help debug a container that isn’t running is the docker logs command.

docker logs <container_name>

This will show the standard out from the running container, which usually gives a clue as to why it exited, more than just the exit code you can see from the container.

Hope this helps with future debugging issues and happy Dockering.