I tend to run my docker containers in the foreground, which happens by default when you run
docker-compose up. I am then rewarded with a steady stream of output from all my containers eg. elasticsearch, kibana, API etc. It can be a bit overwhelming but I have got used to the steady churn of output (kibana can be particularly noisy) and I find it useful to keep an eye on the activity as I have riddled my code with loads of print statements for debugging.
When I accidentally closed my terminal window I felt a bit lost. How was I supposed to be debug? I contemplated stopping all my containers and restarting but the ELK stack can take an age to restart…..
But lo…… there exists
docker attach container_id
If you run
docker container ls you get a list of all your running containers. From here you find the id of the container you are interested in and then run the attach command to take over the terminal.
You can also use the container name eg
docker attach api.