Get container info.
List all containers
Check docker container size:
Check docker container resource usage:
Container operations
Start
Restart
1
| sudo docker restart Nginx
|
Stop
- Stop a container
- Stop all container
1
| sudo docker stop $(sudo docker ps -a -q)
|
Kill
- Kill a container
- Kill all container
1
| sudo docker kill $(sudo docker ps -a -q)
|
Remove
- Remove a container
- Remove all container
1
| sudo docker rm $(sudo docker ps -a -q)
|
File operations
Copy file/directory to container
1
| docker cp <src-path> <container>:<dest-path>
|
e.g. docker cp db:/backup ./
Copy file/directory from container
1
| docker cp <container>:<src-path> <local-dest-path>
|
e.g. docker cp db:/backup ./
Execute command in a running container
- Execute shell
1
| docker exec -it Nginx sh
|
- Dump PostgreSQL db
1
| sudo docker exec db_container_name_xxx /bin/bash -c "pg_dump -U postgres db_name_xxx | gzip -9 > postgres-backup.sql.gz"
|
Reference
Docker Commands