Dockerlab 105 Operating docker container

Step 0 : Create docker hub account.

Step 1 : Open Play with Docker or login in below with your docker hub account.

Step 2 : Click on start

Step 3 : It will start a 4 hr session, click on + ADD NEW INSTANCE

Step 4 : Click in terminal and press enter.

Step 5 : docker run -p 8080:80 nginx

  • -p is to expose container port via host

  • first port after -p is host port, second port is container port

  • Multiple ports can be exposed

  • This command will start container and print logs on terminal

  • you have to type cltr + c to stop container

  • there will be a link 8080 next to open port click on that to access nginx page

Step 6 : docker ps -a

  • list all containers

  • you will see container with image nginx in exited state

Step 7 : docker start <container id>

  • docker start will start container in detach mode

  • use container id from step 6

Step 8 : docker stop <container id>

  • you can stop container with docker stop command

Step 9 : docker run --name app1 -d -p 8080:80 nginx

  • docker run with -d will run container in detach mode

  • --name gives name to container

  • it makes it easy to refer it

Step 10 : docker logs app1

  • docker logs will print container app logs to screen

Step 11 : docker logs -f app1

  • -f option with logs will follow logs

  • this will stream logs on screen

  • use cltr + c to exit from logs

Step 12 : docker restart app1

  • you can restart container if require with this command

Step 13 : docker top app1

  • use top to display running process in container

Step 14 : docker kill app1

  • use docker kill to kill container