alias dc='docker-compose'
alias de='docker-machine env'
alias di='docker images'
alias dl='docker-machine ls'
alias dm='docker-machine'
alias dps='docker ps'
alias dpsa='docker ps -a'
See Docker boilerplates a.k.a templates for most programming language.
Run a Docker container in detached mode and expose port 8080.
$ docker run -d --name my_docker -p 8080:8080 image_name
$ docker inspect -f "{{ .NetworkSettings.IPAddress }}" my_docker
Attach to a running Docker container by ID.
$ docker exec -it 32adfbf6eb62 /bin/bash
Attach to a running Docker container by name and enter a Bash shell.
$ docker exec -it my_docker /bin/bash
To detach use the following escape sequence: CTRL + p CTRL + q
.
docker run --rm -v ${PWD}:/home/jovyan/work jupyter/scipy-notebook
On Windows. Note the above works with PowerShell.
docker run --rm %cd%:/home/jovyan/work jupyter/scipy-notebook
See https://stackoverflow.com/a/41489151
$ docker kill <container_id>
$ docker rm <container_id>
docker rm $(docker ps --filter status=exited -q)
Or, using xargs
:
docker ps --filter status=exited -q | xargs docker rm
$ docker run -d --name my_docker image_name --rm
See single command to stop and remove docker container
$ docker ps -a
$ docker system prune
$ docker rm $(docker ps -a -f status=exited -q)
$ docker rm $(docker ps -a -q)
$ docker images -a
$ docker images --format "table {{.Repository}}\\t{{.Tag}}\\t{{.ID}}"
Store the format in ~/.docker/config.json
. E.g.
{
"psFormat": "table {{.Names}}\\t{{.Image}}\\t{{.RunningFor}} ago\\t{{.Status}}\\t{{.Command}}",
"imagesFormat": "table {{.Repository}}\\t{{.Tag}}\\t{{.ID}}\\t{{.Size}}"
}
See Docker Quicktip #7: docker ps --format.
$ docker rmi $(docker images -q -f dangling=true)
$ docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
$ docker images -q -a | xargs --no-run-if-empty docker rmi
docker rmi $(docker images --filter reference=*/*/my-image*:* -q)
How can I delete Docker images by tag, preferably with wildcarding?
Docker | Using filters
$docker volume ls
$docker volume ls -f dangling=true
$ docker volume prune
$ docker volume prune -f # Bypasses prompt
$ docker volume create db_data
docker run --rm -i -v=postgres-data:/tmp/myvolume busybox find /tmp/myvolume
$ docker-compose up -d --build
$ docker build -t dev:latest .
Docker Cheat Sheet by wsargent
- Awesome Docker
- Docker Bench Security
- Remove Untagged Images From Docker
- What are Docker <none>:<none> images?
- Docker – Clean Up After Yourself!
- How to remove unused Docker containers and images
- docker rmi
- How do you attach and detach from Docker's process?
- How to remove old and unused Docker images
- How to remove <none> images after building
- How To Remove Docker Images, Containers, and Volumes
- How to list the content of a named volume in docker 1.9+?
- How to persist data in a dockerized postgres database using volumes