The container attach command

Suppose you have a running container. It is currently detached from your terminal session. You can use the container attach command to bring that container's executing process to be the foreground process of your terminal session. Let's use the web-server example we used earlier:

# run a container detached
docker container run --detach -it --name web-server1 -p 80:80 nginx

# show that the container is running
docker container ps

# attach to the container
# Usage: docker container attach [OPTIONS] CONTAINER
docker container attach web-server1

# issue a Ctrl + PQ keystroke to detach (except for Docker on Mac, see below for special Mac instructions)

# again, show that the container is running detached.
docker container ps

When you attach to the running container, its executing command becomes the foreground process for your terminal session. To detach from the container, you need to issue a Ctrl + PQ keystroke. If you issue a CtrlC keystroke, the container's executing process will receive a sig-term signal and will terminate, which in turn will exit the container. This is usually not desired. So remember to detach by using a Ctrl + PQ keystroke. 

However, there is a known issue on macOS: for Docker on Mac, the Ctrl + PQ keystroke does not work, and unless you use another parameter, the --sig-proxy=false parameter, on the attach command, you will not be able to detach from the container without terminating it with a Ctrl + C keystroke:

# when you are using Docker for Mac, remember to always add the "--sig-proxy=false" parameter
docker attach --sig-proxy=false web-server1

When you provide the --sig-proxy=false parameter to the attach command, you can issue a Ctrl C keystroke to the attached container and it will detach without sending the sig-term signal to the container process, thus keeping the container running, once again detached from your terminal session:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.137.76