docker attach vs lxc-attach
You're attaching to a container that is running elasticsearch
which isn't an interactive command. You don't get a shell to type in because the container is not running a shell. The reason lxc-attach
works is because it's giving you a default shell. Per man lxc-attach:
If no command is specified, the current default shell of the user running lxc-attach will be looked up inside the container and executed. This will fail if no such user exists inside the container or the container does not have a working nsswitch mechanism.
docker attach
is behaving as expected.
As Ben Whaley notes this is expected behavior.It's worth mentioning though that if you want to monitor the process you can do a number of things:
- Start bash as front process: e.g.
$ES_DIR/bin/elasticsearch && /bin/bash
will give you your shell when you attach. Mainly useful during development. Not so clean :) - Install an ssh server. Although I've never done this myself it's a good option. Drawback is of course overhead, and maybe a security angle. Do you really want ssh on all of your containers? Personally, I like to keep them as small as possible with single-process as the ultimate win.
- Use the log files! You can use
docker cp
to get the logs locally, or better thedocker logs $CONTAINER_ID
command. The latter give you the accumulated stdin/stderr output for the entre lifetime of the container each time though. - Mount the log directory. Just mount a directory on your host and have elasticsearch write to a logfile in that directory. You can have syslog on your host, Logstash, or whatever turns you on ;). Of course, the drawback here is that you are now using your host more than you might like. I also found a nice experiment using logstash in this blog.
FWIW, now that Docker 1.3 is released, you can use "docker exec" to open up a shell or other process on a running container. This should allow you to effectively replace lxc-attach when using the native driver.