Managing Containers
Once an image is built, we can create running instances of these images. These running instances are called as containers.
To run a container, we can use the following command -
docker run -p 3000:80 <image_id>
To stop a container, we can use the following command -
docker stop <container_id>
To list all containers including those which have been stopped, we can use the following command -
docker ps -a
To restart a stopped container, we can use the following command -
*** NOTE: Whenever we execute docker start command, the default mode is detached mode i.e. it does not block the terminal for showing application logs. However, in case of docker run command, the default mode is attached mode i.e. it blocks the terminal, listens to application logs and displays them on the terminal.
To see output of containers -
Deleting containers -
To automatically remove containers when they exit, we can use the “--rm” flag while starting the container -