I am using my PC terminal to start an new ubuntu interactive container using the command
docker run -it ubuntu
Where I am using this to do some command line revision and practice, when I close the terminal window the container still exists in the Windows Desktop.
However when I return to terminal my connection to the docker desktop has been dropped and I am presented with a fresh PowerShell prompt.
Is there some way to use my terminal to re attach to the existing container?
Yes, but not to this specific container as you have created it
A container runs a process, when that process ends, so does the container’s purpose, and lifecycle
When you run docker run -it ubuntu, you create an ubuntu container who’s main process is a bash session, then you attach to it,
When you close your terminal, the bash session ends, and the container is done with its job.
If you want a container running idle, which you can enter and exit out of, you can do this:
The first line creates the container (containername) with tail -f /dev/null being its main process - This watches for changes on the /dev/null file (Which is forever empty); effectively creating an idle container which does nothing and never exits on its own
The second line creates a secondary process in the container, being a bash shell session, and enter it interactively
Exiting that session will end the secondary process, but as the primary one (tail) will still be running, so will the container, and you could docker exec to enter it again as you please