Docker cheat sheet - WordPress.com

6 downloads 211 Views 409KB Size Report
Remove one or more specific images docker rmi . Remove dangling images docker rmi $(docker images -f dan
Docker cheat sheet Containers

Info

Create a container without starting it

docker create

Rename a container

docker rename containerName containerNewName

Locate the name or ID of the containers you want to remove

docker ps -a

List all containers by filter

docker ps -a -f status= Where filter=created, restarting, running, paused, or exited.

See logs of a particular docker container

docker logs containerName

To follow docker log output or tail continuously

docker logs --follow containerName/containerID

to see last n lines of docker logs

docker logs --tail n containerName

Create and start container, run command

docker run -ti --name containerName imageName command

Remove a container automatically when it exits after a run

docker run --rm Image_Name

Start/stop a docker container

docker [start|stop] containerName

Stop all containers

docker stop $(docker ps -a -q)

Remove one or more specific containers

docker rm ID_or_Name ID_or_Name

Remove all exited containers

docker rm $(docker ps -a -f status=exited -q)

Show all images

docker images -a

Build an image from Dockerfile

docker build -t imageName:tag -f Dockerfile

docker rm $(docker ps -a -q)

Download an image

docker pull imageName

Save a running container as an image

docker commit -m “commit message” -a “author” containerName imageName:tag

Remove one or more specific images

docker rmi

Run a command in a docker container docker exec -ti containerName command

Remove dangling images

docker rmi $(docker images -f dangling=true -q)

Author: Sneha Bhat (@snehasbhat) https://thoughtsofsnehabhat.wordpress.com/

Removing images according to a pattern

docker images | grep "pattern" | awk '{print $1}' | xargs docker rm

Remove all images

docker rmi $(docker images -a -q)

Remove all stopped containers Remove dangling volumes

Images

docker volume rm $(docker volume ls -f dangling=true -q)