Images vs Container

  • An Images Is The Application We wan To Run
  • A Container is an instance of that image running as a Process

Running Nginx on Docker

Running nginx on foreground

docker container run –publish 80:80 nginx

Docker engine will look image nginx, and pull from docker hub . Then started a new container for us to use.

command –publish will opened port 80 on the host IP
publish_port: port_on_container
example 8888:80
testing on browser localhost:8888

Running nginx on background

docker container run –publish 80:80 –detach nginx
comman –detach –> running container on background

Setting Name of Container

docker container run –publish 80:80 –detach –name localnginx nginx
➜ ~ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a37c12846046 nginx “/docker-entrypoint.…” 20 seconds ago Up 20 seconds 0.0.0.0:80->80/tcp localnginx

Remove container

docker container rm – f a37
command -f for force