By default, Docker containers run in the foreground.
For example, when you execute the below command in the terminal, terminal gets blocked until the container exited.
docker run ubuntu sleep 1000
If you run the container in detached mode, container starts, and control will get back to the terminal. Use the option -d to run the container in detached mode.
To attach to the running container execute the ‘attach’ command.
Syntax
docker attach {containerId}/{containerName}
$docker run -d ubuntu sleep 1000
e65cb62065df23e995deab943ff637b4953cad01bdb11d195902e1a9c3b076b1
$
$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e65cb62065df ubuntu "sleep 1000" 4 seconds ago Up 3 seconds nostalgic_saha
$
$docker attach e65cb62065df
No comments:
Post a Comment