8.6 KiB
tags
| tags | |||
|---|---|---|---|
|
Docker
Cheet Sheet Commands
Running Containers
| COMMAND | DESCRIPTION |
|---|---|
| `docker run | Start a new container from an image |
| `docker run -it | Start a new container in interactive mode |
| `docker run --rm | Start a new container and remove it when it exits |
| `docker create | Create a new container |
| `docker start ` | Start a container |
| `docker stop ` | Graceful stop a container |
| `docker kill ` | Kill (SIGKILL) a container |
| `docker restart ` | Graceful stop and restart a container |
| `docker pause ` | Suspend a container |
| `docker unpause ` | Resume a container |
| `docker rm ` | Destroy a container |
Container Bulk Management
| COMMAND | DESCRIPTION |
|---|---|
| `docker stop $(docker ps -q)` | To stop all the running containers |
| `docker stop $(docker ps -a -q)` | To stop all the stopped and running containers |
| `docker kill $(docker ps -q)` | To kill all the running containers |
| `docker kill $(docker ps -a -q)` | To kill all the stopped and running containers |
| `docker restart $(docker ps -q)` | To restart all running containers |
| `docker restart $(docker ps -a -q)` | To restart all the stopped and running containers |
| `docker rm $(docker ps -q)` | To destroy all running containers |
| `docker rm $(docker ps -a -q)` | To destroy all the stopped and running containers |
| `docker pause $(docker ps -q)` | To pause all running containers |
| `docker pause $(docker ps -a -q)` | To pause all the stopped and running containers |
| `docker start $(docker ps -q)` | To start all running containers |
| `docker start $(docker ps -a -q)` | To start all the stopped and running containers |
| `docker rm -vf $(docker ps -a -q)` | To delete all containers including its volumes use |
| `docker rmi -f $(docker images -a -q)` | To delete all the images |
| `docker system prune` | To delete all dangling and unused images, containers, cache and volumes |
| `docker system prune -a` | To delete all used and unused images |
| `docker system prune --volumes` | To delete all docker volumes |
Inspect Containers
| COMMAND | DESCRIPTION |
|---|---|
| `docker ps` | List running containers |
| `docker ps --all` | List all containers, including stopped |
| `docker logs ` | Show a container output |
| `docker logs -f ` | Follow a container output |
| `docker top ` | List the processes running in a container |
| `docker diff` | Show the differences with the image (modified files) |
| `docker inspect` | Show information of a container (json formatted) |
Executing Commands
| COMMAND | DESCRIPTION |
|---|---|
| `docker attach ` | Attach to a container |
| `docker cp : ` | Copy files from the container |
| `docker cp :` | Copy files into the container |
| `docker export ` | Export the content of the container (tar archive) |
| `docker exec ` | Run a command inside a container |
| `docker exec -it /bin/bash` | Open an interactive shell inside a container (there is no bash in some images, use /bin/sh) |
| `docker wait ` | Wait until the container terminates and return the exit code |
Images
| COMMAND | DESCRIPTION |
|---|---|
| `docker image ls` | List all local images |
| `docker history | Show the image history |
| `docker inspect | Show information (json formatted) |
| `docker tag | Tag an image |
| `docker commit | Create an image (from a container) |
| `docker import ` | Create an image (from a tarball) |
| `docker rmi | Delete images |
| `docker pull /:` | Pull an image from a registry |
| `docker push /:` | Push and image to a registry |
| `docker search ` | Search an image on the official registry |
| `docker login` | Login to a registry |
| `docker logout` | Logout from a registry |
| `docker save /:` | Export an image/repo as a tarball |
| `docker load` | Load images from a tarball |
Volumes
| COMMAND | DESCRIPTION |
|---|---|
| `docker volume ls` | List all vol1umes |
| `docker volume create ` | Create a volume |
| `docker volume inspect ` | Show information (json formatted) |
| `docker volume rm ` | Destroy a volume |
| `docker volume ls --filter="dangling=true"` | List all dangling volumes (not referenced by any container) |
| `docker volume prune` | Delete all volumes (not referenced by any container) |
| `docker run --rm --volumes-from -v $(pwd):/backup busybox tar cvfz /backup/backup.tar.gz ` | Backup a container |
| `docker run --rm --volumes-from -v $(pwd):/backup busybox sh -c "cd && tar xvfz /backup/backup.tar.gz --strip 1"` | Restore a container from backup |
Docker Install Script
This script is intended as a convenient way to configure docker's package # repositories and to install Docker Engine, This script is not recommended # for production environments. Before running this script, make yourself familiar # with potential risks and limitations, and refer to the installation manual # at https://docs.docker.com/engine/install/ for alternative installation methods.
# # The script:
- Requires root or sudo privileges to run.
- Attempts to detect your Linux distribution and version and configure your package management system for you.
- Doesn't allow you to customize most installation parameters.
- Installs dependencies and recommendations without asking for confirmation.
- Installs the latest stable release (by default) of Docker CLI, Docker Engine, Docker Buildx, Docker Compose, containerd, and runc. When using this script to provision a machine, this may result in unexpected major version upgrades of these packages. Always test upgrades in a test environment before # deploying to your production systems.
- Isn't designed to upgrade an existing Docker installation. When using the script to update an existing installation, dependencies may not be updated to the expected version, resulting in outdated versions.
# # Source code is available at https://github.com/docker/docker-install/
# # Usage # ============================================================================== # #
To install the latest stable versions of Docker CLI, Docker Engine, and their # dependencies:
1. download the script # # $ curl -fsSL https://get.docker.com -o install-docker.sh
2. verify the script's content $ cat install-docker.sh
3. run the script with --dry-run to verify the steps it executes $ sh install-docker.sh --dry-run
4. run the script either as root, or using sudo to perform the installation. $ sudo sh install-docker.sh