Files
the_information_nexus/tech_docs/docker.md
2024-05-01 12:28:44 -06:00

50 lines
3.4 KiB
Markdown

Creating a reference guide for common Docker commands, especially focusing on image management, starting and stopping images, containers, networking, storage, and various lifecycle tasks can be quite helpful. Let's break this down into sections for clarity.
### 1. Docker Image Management
- **List Images**: `docker images` or `docker image ls`
- **Pull an Image**: `docker pull [OPTIONS] NAME[:TAG|@DIGEST]`
- **Push an Image to a Registry**: `docker push NAME[:TAG]`
- **Build an Image from a Dockerfile**: `docker build [OPTIONS] PATH | URL | -`
- **Remove an Image**: `docker rmi [OPTIONS] IMAGE [IMAGE...]`
- **Save an Image to a Tar Archive**: `docker save [OPTIONS] IMAGE [IMAGE...] -o filename.tar`
- **Load an Image from a Tar Archive**: `docker load [OPTIONS]`
### 2. Starting and Stopping Containers
- **Run a Container**: `docker run [OPTIONS] IMAGE [COMMAND] [ARG...]`
- Common options: `-d` (detached), `--name` (assign a name), `-p` (port mapping), `-v` (volume mapping)
- **Stop a Container**: `docker stop [OPTIONS] CONTAINER [CONTAINER...]`
- **Start a Stopped Container**: `docker start [OPTIONS] CONTAINER [CONTAINER...]`
- **Restart a Container**: `docker restart [OPTIONS] CONTAINER [CONTAINER...]`
- **Pause Processes in a Container**: `docker pause CONTAINER`
- **Unpause Processes in a Container**: `docker unpause CONTAINER`
### 3. Working with Containers
- **List Containers**: `docker ps [OPTIONS]`
- `-a`/`--all` to show all containers (default shows just running)
- **Remove a Container**: `docker rm [OPTIONS] CONTAINER [CONTAINER...]`
- **View Logs of a Container**: `docker logs [OPTIONS] CONTAINER`
- **Execute a Command in a Running Container**: `docker exec [OPTIONS] CONTAINER COMMAND [ARG...]`
- **Inspect a Container**: `docker inspect [OPTIONS] CONTAINER [CONTAINER...]`
### 4. Docker Networking
- **List Networks**: `docker network ls`
- **Inspect a Network**: `docker network inspect [OPTIONS] NETWORK [NETWORK...]`
- **Create a Network**: `docker network create [OPTIONS] NETWORK`
- **Remove a Network**: `docker network rm NETWORK [NETWORK...]`
- **Connect a Container to a Network**: `docker network connect [OPTIONS] NETWORK CONTAINER`
- **Disconnect a Container from a Network**: `docker network disconnect [OPTIONS] NETWORK CONTAINER`
### 5. Docker Storage and Volumes
- **Create a Volume**: `docker volume create [OPTIONS] [VOLUME]`
- **List Volumes**: `docker volume ls`
- **Inspect a Volume**: `docker volume inspect [OPTIONS] VOLUME [VOLUME...]`
- **Remove a Volume**: `docker volume rm [OPTIONS] VOLUME [VOLUME...]`
- **Clean up Unused Volumes**: `docker volume prune [OPTIONS]`
### 6. Lifecycle and Miscellaneous Tasks
- **Prune System**: `docker system prune [OPTIONS]`
- Removes stopped containers, dangling images, unused networks, and optionally, unused volumes.
- **Inspect Changes to Files or Directories in a Container's Filesystem**: `docker diff CONTAINER`
- **Copy Files/Folders between a Container and the Local Filesystem**: `docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-` or `docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH`
This guide should serve as a solid foundation for common Docker tasks related to image management, container lifecycle, networking, and storage. Each command might support additional options and arguments to tailor its behavior to your needs. Always refer to the Docker documentation or use the `docker COMMAND --help` command for the most up-to-date and detailed information.