What You'll Learn
Beginner
- The difference between detached and foreground mode
- When to use each
- How to attach to and detach from running containers
Terminalbash
# Foreground: output streams to terminal
docker run nginx
# Detached: runs in background
docker run -d nginxCtrl+C kills the container
When attached, Ctrl+C sends SIGINT. To detach without stopping, use Ctrl+P then Ctrl+Q.Usually docker logs -f is safer
Use docker logs -f <name> to follow logs without risking stopping the container.Practical Exercise
Run a container in detached mode
View logs with
docker logs -fTry attaching with
docker attachKey Takeaways
- Foreground:
Ctrl+Cstops the container. - Detached (
-d): runs in background. - Use detached for servers. Use foreground for debugging.
docker logs -fis safer thandocker attach.
Comments
Comments
Post a Comment