3

I find out an interesting behavior in my docker container, or am I actually use it wrong. Here is what I experience

Everytime when I attach to my container and then exit from my container, my apache service will be shutdown, what I need to do is attach back in and run the apache server again ... is that normal ?? ( my container is just a normal lamp stack )

docker attach 8d009c6b9a3f
root@8d009c6b9a3f# exit   // and my apache will be shut down

FYI, I'm using Mac and docker-machine.

R.R
  • 847
  • 1
  • 9
  • 20

3 Answers3

1

As I explained in "difference between docker attach and docker exec", the command docker attach is for attaching to the existing process.
So when you exit, you exit the existing process (the one running your Apache server).

Try instead using docker exec:

docker exec -it 8d009c6b9a3f bash

That will open a separate process (here a bash), from which you can exit without impacting the entrypoint process.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Do not type exit because it means that you are shutting down the container.

ctrl p + ctrl q (hold ctrl while pressing p and q) to quit the container without exiting

see details http://docs.docker.com/articles/basics/#running-an-interactive-shell

Jry
  • 127
  • 5
-1

You might want to use option -d to run the docker container as a daemon.

docker run -d 
mainframer
  • 20,411
  • 12
  • 49
  • 68
  • The op asks about attaching to already running container, not about running it in the first place. This does not answer the question at all. – ivant Nov 02 '15 at 16:42