Attaching to a running container
We can use the attach
command to attach our terminal’s standard input, output, or error (or any combination of the three) to a running container using the ID or name of the container. Let’s do this for our trivia container:
- Open a new terminal window.
Tip
You may want to use another terminal than the integrated terminal of VS Code for this exercise, as it seems to cause problems with the key combinations that we are going to use. On Mac, use the Terminal app, as an example.
- Run a new instance of the
trivia
Docker image in interactive mode:$ docker container run -it \ --name trivia2 fundamentalsofdocker/trivia:ed2
- Open yet another terminal window and use this command to attach it to the container:
$ docker container attach trivia2
In this case, we will see, every 5 seconds or so, a new quote appearing in the output.
- To quit the container without stopping or killing it, we...