What does it take to run a container
- Things to have
- a docker installed on a system (docker host)
- docker image
- Containers generally have server side applications which are accessible over network.
-
Docker supports port forwarding between container networks and host networks
- Examine the following command where we did static port forwarding (on host 8088 — contianer 80)
docker container run -d --name web1 -p 8088:80 nginx
- Examine the following command where we do dynamic port forwarding
docker container run -d --name web3 -P nginx

What happens during container creation
- examine the command
docker container run -d --name web4 -P httpd - docker checks in the local storage if there is an image called as
httpd:latest - If the image is not found, it tries to connect to a registry. The default registry is docker hub and then pull the image
- Once the image is availabe then a container is created
Intention: I want to delete all containers
docker rm -f $(docker ps -a -q)
Intention: I want to delete all images
docker rmi $(docker images -q)
Lets look into what is running inside containers
- Every container starts by running a command which starts the application inside container
- Your container will be in running state as long as that comand is running
- We can set the command while running the container which will be executed as PID 1
- The ideal first command should start your application and continue to run.
Docker container states

- I will create nginx container

-
Now lets start the nginx container
-
Run => create + start
-
stop
- To remove/delete container we need to stop and delete or force the delete.
# stop and delete
docker stop nginx1
docker rm nginx1
# force
docker rm -f nginx2
