Managing Containers
Common commands overview
Command | Description |
---|---|
docker ps [-a] | Shows currently running containers. Adding -a displays both running and stopped (past) containers. |
docker start | Starts a container from a locally stored image. |
docker stop | Stops a container using Linux SIGTERM , allowing it to terminate gracefully. |
docker restart | Restarts a currently running or stopped container. |
docker kill | Stops a container using Linux SIGKILL , which forces immediate termination. |
docker rm | Removes container files from the host operating system after stopping the container. |
Inspecting container setting
Command | Description |
---|---|
docker ps | Shows the IDs of currently running containers. |
docker inspect <ID> | Inspects the container's details and pipes the output to less for easier reading. |
docker inspect --format='{{.NetworkSettings.IPAddress}}' containername | Displays the IP address of a specific container by its name. |
docker inspect --format containername | Inspects the container and returns details using a specific format defined by the user. |
ps aux on the host machine | Finds the container's PID (Process ID) on the host system. |
Output
controlplane $ docker inspect --format='{{.NetworkSettings.IPAddress}}' xander
172.17.0.2
controlplane $ docker inspect --format='{{.State.Pid}}' xander
47704
controlplane $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
684c0acaa0c5 nginx "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp xander