0

I am running scripts from:

https://www.tutorialspoint.com/docker/docker_storage.htm > Data Volumes

When I want to perform such script:

docker run -d -v /home/docker/demo:/nexus-data --name="volume" sonatype/nexus3

I see on container list that volume container is Up and running but after few seconds it state change to Exited, why?

Wicia
  • 575
  • 3
  • 9
  • 28
  • `docker logs` might tell you something about why the main container’s process exited. Leaving off the `-d` option will run the container in the foreground, which might be more convenient if it’s exiting immediately. – David Maze Aug 14 '18 at 14:25

2 Answers2

1

A docker container exits when the main process finishes. For example if you execute a command that will generate some output - it will execute it (depend of settings save it) and exit.

Dimitar
  • 160
  • 1
  • 1
  • 10
  • So what is difference between given script and "docker run -d --name="volume" sonatype/nexus3" (which is not exiting) in this situation with main process? – Wicia Aug 14 '18 at 11:11
  • The reason it is exiting in the first case is permissions - it tries to create the dir /nexus-data (you can change it to /home/nexus-data and it is fine). That is why in first case container exits with fail and second is ok. Regards (Sorry for the delay). – Dimitar Aug 15 '18 at 04:19
1

You could try to see the live logs of the Docker container with the following command (basically, remove -d and add -it):

docker run -it -v /home/docker/demo:/nexus-data --name="volume" sonatype/nexus3

And try to pin points the exact issue.

Mornor
  • 3,471
  • 8
  • 31
  • 69