We use Docker detached mode (-d) when we want to connect to the container in an interactive mode or we can say when we just want application to be running inside the container. This means, we can start up the container and could use the console after startup for other commands.
It runs the container in the background of your terminal. It does not receive input or display output.
We can use following commands to runs docker container in detached mode and print “Hello World” every one second:-
docker run —name <contName> -d <imgName> /bin/bash -c “while true; do echo Hello World; sleep1; done”
If we want to cross check if the container is running, we can use this command
For checking logs of the container, we can use
docker logs -f
If needed to attach the container and interact with it (go inside container), use following:-
docker run -it <imgName> <entryPoint>
If you want to learn Docker from scratch up to certification level you may refer this playlist:-
- Top 12 Most Popular In-Demand IT/Software Engineering Certification Courses - October 20, 2021
- What are the roles and responsibilities of a site reliability engineer? - October 7, 2021
- What skills are required to become an SRE Engineer OR Site Reliability Engineer? - October 5, 2021