Docker commands
From Tech-Wiki
More actions
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 webserverEquivalent Compose example
version: '2'
services:
myproject:
container_name: webserver
build: ./
volumes:
- /var/www/html:/app
restart: always
network_mode: hostStart 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