Skip to content

Latest commit

 

History

History
58 lines (42 loc) · 1.23 KB

docker-handson-1.md

File metadata and controls

58 lines (42 loc) · 1.23 KB

A non-interactive container

This container displays the time every second.

$ docker run jpetazzo/clock
Sun Jan 12 14:30:52 UTC 2020
Sun Jan 12 14:30:53 UTC 2020
Sun Jan 12 14:30:54 UTC 2020
  • it will run forever it is killed
  • ^Cto stop it

Running a container in the background

$ docker run -d jpetazzo/clock
f31615d81aa4a91ee9cf90a91d0654d8bcb13bfbac7a11ecf0ccb4d42e53e9c6

To see that the container is running:

$ docker ps
  • (truncated) ID of the containers
  • image used to start the container
  • uptime and other information as ports being used, etc.
  • Use -l flag to see the last started container
  • Use -a to see also stopped containers
  • Use -n3to see only last 3

Viewing container logs

$ docker logs <container-id>
  • use --tail 3 to get the last 3 events
  • use -f to follow the log

Stopping a container

$ docker kill <container-id>
  • stops the container immediately, by using the KILL signal
  • a KILL signal cannot be intercepted and will forcibly terminate the container
$ docker stop <container-id>
  • sends a TERM signal to stop a container gracefully
  • if the container has not been stopped after 10 seconds, it will get killed