0% found this document useful (0 votes)
284 views

Docker Cheatsheet Sematext PDF

This document provides a summary of key Docker commands and concepts for container lifecycle management, logging and monitoring, and exploring Docker information. It outlines how to create, start, stop, pause, and delete containers, manage images, set resource limits, map ports, and mount volumes. It also discusses logging container output and metrics with commands like docker logs and docker stats. Explaining concepts like differences between docker ps, docker images, and docker inspect.

Uploaded by

skandams
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
284 views

Docker Cheatsheet Sematext PDF

This document provides a summary of key Docker commands and concepts for container lifecycle management, logging and monitoring, and exploring Docker information. It outlines how to create, start, stop, pause, and delete containers, manage images, set resource limits, map ports, and mount volumes. It also discusses logging container output and metrics with commands like docker logs and docker stats. Explaining concepts like differences between docker ps, docker images, and docker inspect.

Uploaded by

skandams
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Docker Cheatsheet Container lifecycle Logging and monitoring

Tutorial Series Create a container: docker create imageName . Logging on Docker could be challenging - check Top 10 Docker Logging Gotchas.
Create and start a container in one operation: docker run imageName
Remove the container after it stops --rm : docker run --rm alpine ls /usr/lib Show container logs: docker logs containerName
Get started with Docker: https://docs.docker.com/engine/getstarted/ Show only new logs: docker logs -f containerName
Attach the container stdin/stdout to the current terminal use -it : docker run -it ubuntu bash
To mount a directory on the host to a container add -v option, eg Show CPU and memory usage: docker stats
Installation docker run -v $HOSTDIR:$DOCKERDIR imageName Show CPU and memory usage for specific containers: docker stats containerName1 containerName2
To map a container port use -p $HOSTPORT:$CONTAINERPORT : docker run -p 8080:80 nginx Show running processes in a container: docker top containerName
Show Docker events: docker events
Linux To run the container in background use -d swi tch: docker run -d -p 8080:80 nginx
Set container name: docker run --name myContainerName imageName Show storage usage: docker system df
Install script provided by Docker: Example to run nginx web server to serve files from html directory on port 8080: To run a container with a custom logging driver i.e., to syslog use
docker run \ -–log-driver syslog –-log-opt syslog-address=udp://syslog-server:514 \ alpine
echo hello world
curl -sSL https://get.docker.com/ | sh docker run -d -v $(pwd)/html:/usr/share/nginx/html -p 8080:80 --name myNginx .
nginx Use Sematext Docker Agent for log collection. Create Docker Monitoring App & Logs App in Sematext Cloud UI
# access the webserver to get required tokens. Start collecting all container metrics, host metrics, container logs and Docker events:
Or see Installation instructions for your Linux distribution. curl http://localhost:8080

Mac OS X In some cases containers need extended privileges. Add privileges with the --cap_add switch, eg
docker run -d --name sematext-agent-docker \
-e SPM_TOKEN=YOUR_SPM_TOKEN
Download and install Docker For Mac docker run --cap-add SYS_ADMIN imageName . The flag --cap_drop is used to remove priviledges -e LOGSENE_TOKEN=YOUR_LOGSENE_TOKEN \
-v /var/run/docker.sock:/var/run/docker.sock \
Rename a container: docker rename name newName sematext/sematext-agent-docker
Create Docker VM with Docker Machine
Delete a container: docker rm containerID
You can use Docker Machine to: The command above will collect all container metrics, host metrics, container logs and Docker events.
Delete all unused containers: docker ps -q -a | xargs docker rm
Install and run Docker on Mac or Windows Remove the volumes associated with a container: docker rm -v containerName Exploring Docker information
Provision and manage multiple remote Docker hosts
Update container resource limits: docker update --cpu-shares 512 -m 300M
Provision Swarm clusters
Show Docker info: docker info
List running containers: docker ps
A simple example to create a local Docker VM with VirtualBox: List all containers: docker ps -a
List all containers: docker ps -a List all images: docker image ls
Show all container details: docker inspect containerName
docker-machine create --driver=virtualbox default List all container IDs: docker ps -q -a
docker-machine ls Show changes in the container's files: docker diff containerName
eval "$(docker-machine env default)"
Starting and stopping containers Manage Docker images
Then start up a container: Start a container: docker start containerName
List all images: docker images
Start a container: docker stop containerName
Search in registry for an image: docker search searchTerm pulls an image from registry to local machine
Restart a container: docker restart containerName
docker run alpine echo "hello-world" Pull image from a registry: docker pull imageName
Pause a container ("freeze"): docker pause containerName
Create image from Dockerfile: docker build
Unpause a container: docker unpause containerName
That's it, you have a running Docker container. Remove image: docker rmi imageName
Stop and wait for termination: docker wait containerName
Export container into tgz file: docker export myContainerName -o myContainerName
Kill a container (sends SIGKILL): docker kill containerName
Create an image from a tgz file: docker import file

Executing commands in containers and apply changes


Data cleanup
Execute a command in a container: docker exec -it containerName command
Copy files or folders between a container and the local filesystem: Data Management Commands:
docker cp containerName:path localFile or docker cp localPath containerName:path
Remove unused resources: docker system prune
METRICS, EVENTS and LOGS Apply changes in container file systems: docker commit containerName Remove unused volumes: docker volume prune
Remove unused networks: docker network prune
Docker networks Remove unused containers: docker container prune
START YOUR FREE TRIAL Remove unused images: docker image prune
List existing networks: docker network ls
Create a network: docker network create netName
Sematext is Docker monitoring and logging Remove network: docker network rm netName
certified partner
Show network details: docker network inspect
Connect container to a network: docker network connect networkName containerName
Disconnect network from container: docker network disconnect networkName containerName

Full-stack visibility. Actionable insights. Single pane of glass.

You might also like