By Lukas Aichbauer & Ivan Popovic | March 21, 2024 | 2 min watch
Learn all the commands needed to start, manage and interact with a Docker Container in 132 seconds.
docker run <image-name/image-id>
β start a Docker container (a running instance of a Docker image)
--detach
β add this flag to the docker run
command if you want to run the container in a background process
--publish <host-port>:<container-port>
β add this flag to the docker run
command if you want to forward a container port to the host system (e.g., --publish 3000:3000
). This is useful if you want to access the program running in your container from the host system (e.g., a REST API hosted on port 3000 in the container)
docker stop <container-name/container-id>
β stop a Docker container
docker rm <container-name/container-id>
β remove a Docker container completely
docker restart <container-name/container-id>
β restart a stopped Docker container (a removed container cannot be restarted)
docker container ls
β list all running containers
--all
β add this flag to the docker container ls
command if you want to list all containers, including stopped containers