Skip to content

Instantly share code, notes, and snippets.

@ShannonScott
Last active March 25, 2020 23:30
Show Gist options
  • Save ShannonScott/d6869d3d51e8bfe87999d0c5664a782c to your computer and use it in GitHub Desktop.
Save ShannonScott/d6869d3d51e8bfe87999d0c5664a782c to your computer and use it in GitHub Desktop.
[Docker Notes] Docker notes. #tags: docker, notes

Docker Notes

Notes on using Docker in practice.

Override entry point in run command

Add the following option: --entrypoint "/bin/bash"

Access running container

docker exec -it <container-id-or-name> /bin/bash

Docker command for all running containers

Issue a command (for example docker stop) for all running containers:

docker ps --format '{{.Names}}' | xargs docker stop

Docker command for any container (running or otherwise)

docker container ls -a --format '{{.Names}}' | xargs docker rm

Docker system

Get system events for the last hour:

docker system events --since='1h'

Get disk usage:

docker system df

Docker Image / Container Labels

Links

Inspect Image/Container for Labels

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 running containers

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

WIP - search docker logs with xargs

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>

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment