0

I'm a new to Docker. Tried to start docker container with simple java code.

I saw the printing Hello-World, that means that my code is executed, but the container always exits.

This is my Dockerfile:

FROM nicb/alpine-openjdk8-jre
COPY HelloDockerTest.jar /
CMD java -jar HelloDockerTest.jar

FROM nicb/alpine-openjdk8-jre - this is image from remote repository

The steps that I do are:

1. docker build -t testtt .
2. docker run -i testtt
3. docker start 2520e85b333a

In the last step I see the printing "Hello World" but when I do docker ps I see nothing.

What did I do wrong?

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Orlov Andrey
  • 262
  • 4
  • 18
  • 2
    Does this answer your question? [Why docker container exits immediately](https://stackoverflow.com/questions/28212380/why-docker-container-exits-immediately) – leopal Jan 14 '20 at 15:02
  • You don't do nothing incorrect, that's the way it should be. The docker executes the commands and then ... it's gone. – aran Jan 14 '20 at 15:08

1 Answers1

0

This is the correct expected behaviour of Docker. The ENTRYPOINT or CMD (for the most part) should run a command that runs forever or until a failure scenario occurs.

If you were to change your CMD line to CMD java -jar HelloDockerTest.jar && tail -f /dev/null your container wouldn't exit. Or if you had started a java application that continues to run, you will see the same behaviour.

leeman24
  • 2,729
  • 3
  • 29
  • 42