Jump to content
Toggle menu
  • 51 articles
  • 24 files
  • 4 users
  • 750 edits
Tech-Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Docker commands

From Tech-Wiki


Common Docker CLI and Compose examples for creating, monitoring, pruning and troubleshooting containers.

!
Docker group membership is highly privileged
Adding a user to the docker group normally grants broad control over the Docker daemon and host. Limit membership to trusted administrators.

Add a user to the docker group

>_Add an existing user
usermod -a -G docker ec2-user

Create and start a container from the CLI

docker create \
  --name=webserver --net=host -e VERSION=latest \
  -e PUID=$(id -u docker) -e PGID=$(id -g docker) \
  -v /var/www/html:/app:ro \
  --restart unless-stopped nginx

docker start webserver

Equivalent Compose example

version: '2'
services:
  myproject:
    container_name: webserver
    build: ./
    volumes:
      - /var/www/html:/app
    restart: always
    network_mode: host

Start the Compose project:

>_Start the project
docker-compose up -d

Monitor containers

>_Container resource usage
docker stats
>_Processes inside a container
docker top container1

Remove unused Docker data

!
Prune removes unused Docker data
docker system prune -a removes unused images as well as other unused Docker objects. Review what is required before running it on a shared host.
>_Prune unused data
docker system prune -a

Troubleshoot inside a container

>_Open a shell
docker exec -it webserver /bin/bash

See also