diff --git a/README b/README index 6d05ff2cc879f287e0299228d6aacef2db7154cf..3bf0688f32d93fe91e066acfd71288f6249d0690 100644 --- a/README +++ b/README @@ -239,3 +239,43 @@ Here are some useful options you might want to use: | -h | <hostname> | set the container's hostname | | -p | <hport>:<cport> | map host's <hport> to container's <cport> | | -v | <hdir>:<cdir> | mount host's <hdir> on <cdir> | + + +Executing Commands in a Running Container +========================================= + +Sometimes you need to examine what's going on inside a container. That's +where the *exec* command can come in handy. It's a lot like *run* but for +a container, rather than an image. Here's a common thing you might want to +do: + + docker run --name=svc_instance my_service:latest + docker exec -ti svc_instance /bin/bash + +What this does is to first start a container using the latest version of +the image my_service, and name the container svc_instance, and then to +execute an interactive bash shell on that container. You don't have to exec an +interactive command, though. There may be times when you want to run something +like: + + docker exec svc_instance touch /var/cache/magic_file + +in order to change the behavior of a running process. As with the other commands +we've looked at, "docker exec" is now an alias for "docker container exec". + + +Getting Process Output +====================== + +Many processes send their output to STDOUT or STDERR. Since there's no TTY +available to the process in a container, this output would generally be lost. +Docker saves this output for you, however, and you can retrieve these by +running + + docker logs <container> + docker container logs <container> + +The first command is now an alias for the second command. There are a number +of options, such as "--since" to limit the timeframe of the logs returned, +"-f" to continue to follow the logs rather than just dumping their current +contents and exiting, and "-t" to show timestamps at the beginnings of lines.