General Docker commands

This gets real time docker events from the server. Options include filter, format, since, and until. To exit, use Control C

docker ps

docker ps -a

List running containers (-a will list all existing containers)

docker images

List the images

docker inspect imagename

Inspect an image - needs fully qualified name You can pipe it through grep to get specific information

docker exec -it containername /bin/bash

Connect to a running docker container

docker pause / unpause

Pauses / unpauses the processes within one or more containers. Note that if a container is paused, it must be unpaused (not started).

docker stats

Shows running statistics about docker containers. Note on later versions of docker (tested on 17.12), by default this command will contain the container name rather than the id.

docker stats --format "table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}"

Docker stats command formatted to be more easily readable

docker system prune

WARNING - this will remove all stopped containers, all networks not used by at least one container, build cache, and all dangling images. USE WITH CAUTION. Since removing volumes is a destructive event (all data will be lost in the volume), it is not a default operation. To remove volumes, a flag can be passed (--volumes), or the volume prune command used (see volume commands). Other flags include --all or -a (to remove ALL unused images), and --force or -f (to override the confirmation prompt). This can also be used in conjunction with other commands for a complete docker system refresh (stop and remove all containers and prune)

Commands can be piped through grep to narrow the results

Docker-compose commands

Command

Description

docker-compose version

List information about the docker-compose version

docker-compose --version

List limited information

docker-compose up -d

Start all services defined in the docker-compose file - create and start the container(s)

docker-compose up -d servicename

Start a specific service defined in the docker-compose file

docker-compose ps

List all running containers in the current docker-compose project directory; including name, command, state, and ports

docker-compose events

Streams events for containers in the compose project. This is similar to docker events, but there are no filters allowed other than ---json. Exit by using Control C

docker-compose images

Similar to docker-compose ps; lists the container name and information about the image(s)

docker-compose config

Validate and view the compose file complete/combined with other configuration files such as the docker-compose.override.yml

docker-compose logs

View the container logs. Specific containers can be listed. Use the -t option to show timestamps, and --tail="xx" to indicate the number of lines to show from the end of the logs for each container. To follow the log, use the -f option (and control C to end).

docker-compose pause/unpause

Pauses the running containers. Note that the unpause (not start) command has to be used in order to restore the containers to their normal state.

docker-compose start/restart

Start or restart existing containers

docker-compose stop

Stop containers (note this does not remove the containers)

docker-compose rm

Remove a specific service/container

docker-compose rm -fv

Remove a specific service/container and the volume (use with extreme caution)

docker-compose down

Stop AND remove containers,networks, volumes, and images created by docker-compose up. See parameters - by default does not remove volumes

Volume commands

Command

Description

docker volume ls

List existing volumes

docker volume inspect [volume name]

Information about the specific environment

docker volume create

Create a volume - there are various parameters to use here

docker volume rm [volume name]

Remove a specific unused volume

docker volume prune

Remove all currently unused volumes - use with extreme caution as a container might have been removed (making the volume removable), but the intent may be to reuse the volume with another container.