Notes on using Docker in practice.
Add the following option: --entrypoint "/bin/bash"
docker exec -it <container-id-or-name> /bin/bash
Issue a command (for example docker stop
) for all running containers:
docker ps --format '{{.Names}}' | xargs docker stop
docker container ls -a --format '{{.Names}}' | xargs docker rm
Get system events for the last hour:
docker system events --since='1h'
Get disk usage:
docker system df
- How to Tag Docker Images with Git Commit Information
- Let’s make your Docker Image better than 90% of existing ones
- Use labels on your Docker images
Inspect a container or image for its metadata, filter down to labels with jq
.
docker inspect <object-hash-or-name> | jq '.[].ContainerConfig.Labels'
Search logs for all docker containers for a given string.
SEARCH=<insert search string here>
for id in `docker ps -q`
do
echo $id
docker logs $id |& grep $SEARCH
done
This works, but does not specify the container from which the results were found. There is a -t
option to xargs, but the grep will strip the output.
docker ps -q | xargs -L 1 -I % docker logs % |& grep <insert search string here>