the container process, is attached to a process in the image (/bin/bash in some cases) when we exit we stop the process, so the container stops as well
to keep it running, i can specific the command that i want it to run
tail -f /dev/null is the command (it will get PID 1 in the container)
-d is the detach
in this case, tail -f /dev/null will keep running the container
dockerrun--namejamecho-dubuntutail-f/dev/null
to run a command in a running container (perritos is the name of the container)dockerexec-itperritosbash
to verify when logged in into the container ps -aux
to exit: exit
the container will keep running, because the main process has not stopped yet
to stop it
docker stop <containerName> or in mac: docker kill <containerName>
Example:
docker stop perritos
docker stop <container_id> or docker stop <container_name>
or get the pid ion the local Linux system
docker inspect --format '{{.State.Pid}}' perritos
and kill the process using the pid obtained
kill -9 <pid>
to run a stopped container
docker start <container_name>
docker start perritos
check docker ps -a
to log into the previous started container (iamge name: perritosm, command: bash)
docker exec -it perritos bash
to exit:
exit
to stop it
docker stop <containerName> or in mac: docker kill <containerName>
to check the output of a command (it the command is tail -f /dev/null the terminal might be stucked, recommended using with bash)