### Multi-stage Dockerfile Example Source: https://docs.docker.com/reference/cli/docker/buildx/build This Dockerfile demonstrates a multi-stage build with stages for base, install, test, and release. It utilizes buildx features like `--mount`. ```dockerfile # syntax=docker/dockerfile:1 FROM oven/bun:1 AS base WORKDIR /app FROM base AS install WORKDIR /temp/dev RUN --mount=type=bind,source=package.json,target=package.json \ --mount=type=bind,source=bun.lockb,target=bun.lockb \ bun install --frozen-lockfile FROM base AS test COPY --from=install /temp/dev/node_modules node_modules COPY . . RUN bun test FROM base AS release ENV NODE_ENV=production COPY --from=install /temp/dev/node_modules node_modules COPY . . ENTRYPOINT ["bun", "run", "index.js"] ``` -------------------------------- ### Install and configure a plugin Source: https://docs.docker.com/reference/cli/docker/plugin/install Installs the `vieux/sshfs` plugin, sets the `DEBUG` environment variable to `1`, and prompts for permission confirmation. This example demonstrates pulling from Docker Hub, setting parameters, and enabling the plugin. ```console $ docker plugin install vieux/sshfs DEBUG=1 Plugin "vieux/sshfs" is requesting the following privileges: - network: [host] - device: [/dev/fuse] - capabilities: [CAP_SYS_ADMIN] Do you grant the above permissions? [y/N] y vieux/sshfs ``` -------------------------------- ### Install Go SDK Source: https://docs.docker.com/reference/api/engine/sdk Use this command to install the Go SDK for Docker. Ensure you have a recent version of Go installed. ```bash $ go get github.com/moby/moby/client ``` -------------------------------- ### Bootstrap Docker Daemon Instance Source: https://docs.docker.com/reference/cli/dockerd Example command to start a secondary, isolated Docker daemon instance without network capabilities. ```console $ sudo dockerd \ -H unix:///var/run/docker-bootstrap.sock \ -p /var/run/docker-bootstrap.pid \ --iptables=false \ --ip-masq=false \ --bridge=none \ --data-root=/var/lib/docker-bootstrap \ --exec-root=/var/run/docker-bootstrap ``` -------------------------------- ### Example Docker events output Source: https://docs.docker.com/reference/cli/docker/system/events This is an example of the output seen in the shell listening for Docker events after creating, starting, and stopping a container. ```console 2017-01-05T00:35:58.859401177+08:00 container create 0fdb48addc82871eb34eb23a847cfd033dedd1a0a37bef2e6d9eb3870fc7ff37 (image=alpine:latest, name=test) 2017-01-05T00:36:04.703631903+08:00 network connect e2e1f5ceda09d4300f3a846f0acfaa9a8bb0d89e775eb744c5acecd60e0529e2 (container=0fdb...ff37, name=bridge, type=bridge) 2017-01-05T00:36:04.795031609+08:00 container start 0fdb...ff37 (image=alpine:latest, name=test) 2017-01-05T00:36:09.830268747+08:00 container kill 0fdb...ff37 (image=alpine:latest, name=test, signal=15) 2017-01-05T00:36:09.840186338+08:00 container die 0fdb...ff37 (exitCode=143, image=alpine:latest, name=test) 2017-01-05T00:36:09.880113663+08:00 network disconnect e2e...29e2 (container=0fdb...ff37, name=bridge, type=bridge) 2017-01-05T00:36:09.890214053+08:00 container stop 0fdb...ff37 (image=alpine:latest, name=test) ``` -------------------------------- ### Install Python SDK manually Source: https://docs.docker.com/reference/api/engine/sdk If pip is not available, you can manually install the Python SDK by downloading the package, extracting it, and running the setup script. ```bash python setup.py install ``` -------------------------------- ### Use cache source examples Source: https://docs.docker.com/reference/cli/docker/buildx/build Examples of using various cache backends with the --cache-from flag. ```console $ docker buildx build --cache-from=user/app:cache . $ docker buildx build --cache-from=user/app . $ docker buildx build --cache-from=type=registry,ref=user/app . $ docker buildx build --cache-from=type=local,src=path/to/cache . $ docker buildx build --cache-from=type=gha . $ docker buildx build --cache-from=type=s3,region=eu-west-1,bucket=mybucket . ``` -------------------------------- ### Good Casing Example (All Uppercase) in Dockerfile Source: https://docs.docker.com/reference/build-checks/consistent-instruction-casing Use all uppercase for Dockerfile instruction keywords for better readability. This example demonstrates correct casing for FROM, RUN, and ENTRYPOINT. ```dockerfile FROM alpine RUN echo hello > /greeting.txt ENTRYPOINT ["cat", "/greeting.txt"] ``` -------------------------------- ### docker container exec Examples Source: https://docs.docker.com/reference/cli/docker/exec Practical examples demonstrating the usage of the `docker container exec` command. ```APIDOC ### Examples #### Run `docker exec` on a running container 1. Start a container: ```bash $ docker run --name mycontainer -d -i -t alpine /bin/sh ``` 2. Execute a command on the container: ```bash $ docker exec -d mycontainer touch /tmp/execWorks ``` 3. Execute an interactive `sh` shell on the container: ```bash $ docker exec -it mycontainer sh ``` #### Set environment variables for the exec process (`--env`, `-e`) ```bash $ docker exec -e VAR_A=1 -e VAR_B=2 mycontainer env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=f64a4851eb71 VAR_A=1 VAR_B=2 HOME=/root ``` #### Escalate container privileges (`--privileged`) See `docker run --privileged`. #### Set the working directory for the exec process (`--workdir`, `-w`) 1. Default working directory: ```bash $ docker exec -it mycontainer pwd / ``` 2. Specify working directory: ```bash $ docker exec -it -w /root mycontainer pwd /root ``` ``` -------------------------------- ### Invoke frontend method example Source: https://docs.docker.com/reference/cli/docker/buildx/build Example of using the --call flag to list available frontend methods. ```console $ docker buildx build -q --call=subrequests.describe . NAME VERSION DESCRIPTION outline 1.0.0 List all parameters current build target supports targets 1.0.0 List all targets current build supports subrequests.describe 1.0.0 List available subrequest types ``` -------------------------------- ### Start Docker Desktop Source: https://docs.docker.com/reference/cli/docker/desktop/start Starts the Docker Desktop application. You can use options to control its behavior. ```APIDOC ## docker desktop start ### Description Start Docker Desktop ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Options #### Command Line Options - **-d**, **--detach** (boolean) - Optional - Do not synchronously wait for the requested operation to complete. - **--timeout** (integer) - Optional - Terminate the running command after the specified timeout with a non-zero exit code. A value of zero (the default) or -1 means no timeout. ### Usage Example ```bash docker desktop start docker desktop start -d docker desktop start --timeout 60 ``` ``` -------------------------------- ### Good Casing Example (All Lowercase) in Dockerfile Source: https://docs.docker.com/reference/build-checks/consistent-instruction-casing Alternatively, use all lowercase for Dockerfile instruction keywords. This example shows correct lowercase casing for FROM, RUN, and ENTRYPOINT. ```dockerfile from alpine run echo hello > /greeting.txt entrypoint ["cat", "/greeting.txt"] ``` -------------------------------- ### Select Go platform with docker init Source: https://docs.docker.com/reference/cli/docker/init Example of selecting the Go platform and providing necessary details like Go version, main package directory, and server port. ```console ? What application platform does your project use? Go ? What version of Go do you want to use? 1.20 ? What's the relative directory (with a leading .) of your main package? . ? What port does your server listen on? 3333 CREATED: .dockerignore CREATED: Dockerfile CREATED: compose.yaml CREATED: README.Docker.md ✔ Your Docker files are ready! Take a moment to review them and tailor them to your application. When you're ready, start your application by running: docker compose up --build Your application will be available at http://localhost:3333 Consult README.Docker.md for more information about using the generated files. ``` -------------------------------- ### Install a tool into the toolbox Source: https://docs.docker.com/reference/cli/docker/debug Use the `install` command within `docker debug` to add packages from search.nixos.org to your toolbox. This does not modify the actual image or container. ```console $ docker debug nginx ... docker > install nmap Tip: You can install any package available at: https://search.nixos.org/packages. installing 'nmap-7.93' these 2 paths will be fetched (5.58 MiB download, 26.27 MiB unpacked): /nix/store/brqjf4i23fagizaq2gn4d6z0f406d0kg-lua-5.3.6 /nix/store/xqd17rhgmn6pg85a3g18yqxpcya6d06r-nmap-7.93 copying path '/nix/store/brqjf4i23fagizaq2gn4d6z0f406d0kg-lua-5.3.6' from 'https://cache.nixos.org'... copying path '/nix/store/xqd17rhgmn6pg85a3g18yqxpcya6d06r-nmap-7.93' from 'https://cache.nixos.org'... building '/nix/store/k8xw5wwarh8dc1dvh5zx8rlwamxfsk3d-user-environment.drv'... docker > nmap --version Nmap version 7.93 ( https://nmap.org ) Platform: x86_64-unknown-linux-gnu Compiled with: liblua-5.3.6 openssl-3.0.11 libssh2-1.11.0 nmap-libz-1.2.12 libpcre-8.45 libpcap-1.10.4 nmap-libdnet-1.12 ipv6 Compiled without: Available nsock engines: epoll poll select ``` ```console $ docker debug hello-world ... docker > nmap --version Nmap version 7.93 ( https://nmap.org ) Platform: x86_64-unknown-linux-gnu Compiled with: liblua-5.3.6 openssl-3.0.11 libssh2-1.11.0 nmap-libz-1.2.12 libpcre-8.45 libpcap-1.10.4 nmap-libdnet-1.12 ipv6 Compiled without: Available nsock engines: epoll poll select docker > exit ``` -------------------------------- ### Build and Run Example (Runtime Expansion) Source: https://docs.docker.com/reference/dockerfile Shows how to build the image and run the container, providing an environment variable at runtime to influence the script's output when build-time expansion is disabled. ```console $ docker build -t heredoc . $ docker run -e FOO=world heredoc ``` -------------------------------- ### Build and Run Example (Variable Expansion) Source: https://docs.docker.com/reference/dockerfile Demonstrates building the Docker image and running the container to observe the variable expansion at build time. ```console $ docker build -t heredoc . $ docker run heredoc ``` -------------------------------- ### Inspecting processes after starting Apache Source: https://docs.docker.com/reference/dockerfile Shows how to inspect processes within a running container using 'docker exec'. This example lists processes after Apache has been started by the script. ```console $ docker exec -it test ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.1 0.0 4448 692 ? Ss+ 00:42 0:00 /bin/sh /run.sh 123 cmd cmd2 root 19 0.0 0.2 71304 4440 ? Ss 00:42 0:00 /usr/sbin/apache2 -k start www-data 20 0.2 0.2 360468 6004 ? Sl 00:42 0:00 /usr/sbin/apache2 -k start www-data 21 0.2 0.2 360468 6000 ? Sl 00:42 0:00 /usr/sbin/apache2 -k start root 81 0.0 0.1 15572 2140 ? R+ 00:44 0:00 ps aux ``` -------------------------------- ### Environment File Example (Bash) Source: https://docs.docker.com/reference/compose-file/services Example of an environment file in bash format, showing variable assignments, quoted values, and comments. Lines starting with '#' and blank lines are ignored. ```bash # Set Rails/Rack environment RACK_ENV=development VAR="quoted" ``` -------------------------------- ### Dockerfile with Descriptions Source: https://docs.docker.com/reference/cli/docker/build Example Dockerfile demonstrating how to add descriptions for build targets and arguments using comments preceding `FROM` and `ARG` instructions. ```dockerfile # syntax=docker/dockerfile:1 # GO_VERSION sets the Go version for the build ARG GO_VERSION=1.22 # base-builder is the base stage for building the project FROM golang:${GO_VERSION} AS base-builder WORKDIR /test COPY --from=build /out ./public ``` -------------------------------- ### Create and start an interactive container Source: https://docs.docker.com/reference/cli/docker/container/create Creates an interactive container with a pseudo-TTY, then starts and attaches to it. This process is functionally equivalent to running a container directly. ```console $ docker container create -i -t --name mycontainer alpine 6d8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752 $ docker container start --attach -i mycontainer / # echo hello world hello world ``` ```console $ docker run -it --name mycontainer2 alpine / # echo hello world hello world ``` -------------------------------- ### Select Node platform with docker init Source: https://docs.docker.com/reference/cli/docker/init Example of selecting the Node platform and configuring details such as Node version, package manager, build command, and server port. ```console ? What application platform does your project use? Node ? What version of Node do you want to use? 18 ? Which package manager do you want to use? yarn ? Do you want to run "yarn run build" before starting your server? Yes ? What directory is your build output to? (comma-separate if multiple) output ? What command do you want to use to start the app? node index.js ? What port does your server listen on? 8000 CREATED: .dockerignore CREATED: Dockerfile CREATED: compose.yaml CREATED: README.Docker.md ✔ Your Docker files are ready! Take a moment to review them and tailor them to your application. When you're ready, start your application by running: docker compose up --build Your application will be available at http://localhost:8000 Consult README.Docker.md for more information about using the generated files. ``` -------------------------------- ### Start Docker Daemon with Authorization Plugins Source: https://docs.docker.com/reference/cli/dockerd Use this command to start the Docker daemon with one or more authorization plugins. The PLUGIN_ID can be a plugin name or a path to its specification file. ```console sudo dockerd --authorization-plugin=plugin1 --authorization-plugin=plugin2,... ``` -------------------------------- ### Create a config with labels Source: https://docs.docker.com/reference/cli/docker/config/create This example demonstrates how to create a config and assign labels to it using the `--label` option. Multiple labels can be applied. ```console $ docker config create \ --label env=dev \ --label rev=20170324 \ my_config ./config.json ``` ```console eo7jnzguqgtpdah3cm5srfb97 ``` -------------------------------- ### GET /info Source: https://docs.docker.com/reference/api/engine/version-history Returns system-wide information. In v1.46, it includes a `Containerd` field. Warnings about iptables are no longer included starting v1.47. ```APIDOC ## GET /info ### Description Returns system-wide information about the Docker daemon. ### Method GET ### Endpoint /info ### Response #### Success Response (200) - **ID** (string) - The daemon ID. - **Containers** (integer) - The number of containers. - **ContainersRunning** (integer) - The number of running containers. - **ContainersPaused** (integer) - The number of paused containers. - **ContainersStopped** (integer) - The number of stopped containers. - **Images** (integer) - The number of images. - **Driver** (string) - The storage driver used. - **DriverStatus** (array) - Status of the storage driver. - **DockerRootDir** (string) - The root directory for Docker. - **EphemeralStorageDriver** (string) - The ephemeral storage driver. - **Sockets** (array) - List of Docker sockets. - **Warnings** (array) - System warnings. - **Containerd** (object) - Information about containerd (v1.46+). - **Address** (string) - Address of the containerd API socket. - **Namespace** (string) - Namespaces used by containerd. #### Response Example { "ID": "docker-daemon-id", "Containers": 10, "ContainersRunning": 5, "ContainersPaused": 0, "ContainersStopped": 5, "Images": 50, "Driver": "overlay2", "DriverStatus": [ ["Backing Filesystem", "extfs"] ], "DockerRootDir": "/var/lib/docker", "EphemeralStorageDriver": "overlayfs", "Sockets": ["unix:///var/run/docker.sock"], "Warnings": [], "Containerd": { "Address": "/run/containerd/containerd.sock", "Namespace": "default" } } ``` -------------------------------- ### Initialize a generic project with docker init Source: https://docs.docker.com/reference/cli/docker/init Output for selecting the 'Other' platform option. ```console ? What application platform does your project use? Other CREATED: .dockerignore CREATED: Dockerfile CREATED: compose.yaml CREATED: README.Docker.md ✔ Your Docker files are ready! Take a moment to review them and tailor them to your application. When you're ready, start your application by running: docker compose up --build Consult README.Docker.md for more information about using the generated files. ``` -------------------------------- ### Checkpoint and restore workflow example Source: https://docs.docker.com/reference/cli/docker/checkpoint Demonstrates running a container, creating a checkpoint, and restoring it to resume the process. ```console $ docker run --security-opt=seccomp:unconfined --name cr -d busybox /bin/sh -c 'i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done' abc0123 $ docker checkpoint create cr checkpoint1 # $ docker start --checkpoint checkpoint1 cr abc0123 ``` -------------------------------- ### Running Nginx container Source: https://docs.docker.com/reference/dockerfile This command starts a container from the nginx image, exposing port 80. It is a common example for demonstrating container execution. ```console $ docker run -i -t --rm -p 80:80 nginx ``` -------------------------------- ### Create, start, wait, and get logs for a container using cURL Source: https://docs.docker.com/reference/api/engine/sdk This sequence of cURL commands demonstrates interacting with the Docker API directly to create, start, wait for, and retrieve logs from a container. It assumes cURL version 7.50.0 or above and a Unix socket connection. ```console $ curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" \ -d '{"Image": "alpine", "Cmd": ["echo", "hello world"]}' \ -X POST http://localhost/v1.54/containers/create {"Id":"1c6594faf5","Warnings":null} $ curl --unix-socket /var/run/docker.sock -X POST http://localhost/v1.54/containers/1c6594faf5/start $ curl --unix-socket /var/run/docker.sock -X POST http://localhost/v1.54/containers/1c6594faf5/wait {"StatusCode":0} $ curl --unix-socket /var/run/docker.sock "http://localhost/v1.54/containers/1c6594faf5/logs?stdout=1" hello world ``` -------------------------------- ### Mount non-existent host directory Source: https://docs.docker.com/reference/cli/docker/run When a host directory for a bind mount does not exist, Docker automatically creates it. This example mounts `/doesnt/exist` before starting the container. ```bash $ docker run -v /doesnt/exist:/foo -w /foo -i -t ubuntu bash ``` -------------------------------- ### Create and Run Sandbox Immediately Source: https://docs.docker.com/reference/cli/docker/sandbox/create This demonstrates creating a sandbox with a custom name and then running it. Alternatively, `docker sandbox run` can create and run in a single step. ```console $ docker sandbox create --name my-sandbox claude ~/my-project $ docker sandbox run my-sandbox ``` -------------------------------- ### Create manifest list help Source: https://docs.docker.com/reference/cli/docker/manifest Displays the help documentation for the docker manifest create command. ```console Usage: docker manifest create MANIFEST_LIST MANIFEST [MANIFEST...] Create a local manifest list for annotating and pushing to a registry Options: -a, --amend Amend an existing manifest list --insecure Allow communication with an insecure registry --help Print usage ``` -------------------------------- ### RUN --network=none Example Source: https://docs.docker.com/reference/dockerfile Use `--network=none` to run a command with no network access. This is useful for isolating external effects, such as installing packages only from a local tarball. ```dockerfile # syntax=docker/dockerfile:1 FROM python:3.6 ADD mypackage.tgz wheels/ RUN --network=none pip install --find-links wheels mypackage ``` -------------------------------- ### Add MCP servers to a profile Source: https://docs.docker.com/reference/cli/docker/mcp/profile/server/add Examples demonstrating how to add servers from catalogs, OCI references, registry references, or a mix of sources. ```bash docker mcp profile server add dev-tools --server catalog://mcp/docker-mcp-catalog/github+obsidian ``` ```bash docker mcp profile server add my-profile --server docker://my-server:latest ``` ```bash docker mcp profile server add my-profile --server http://registry.modelcontextprotocol.io/v0/servers/71de5a2a-6cfb-4250-a196-f93080ecc860 ``` ```bash docker mcp profile server add dev-tools --server catalog://mcp/docker-mcp-catalog/github+obsidian --server docker://my-server:latest ``` -------------------------------- ### List All Servers Across Profiles Source: https://docs.docker.com/reference/cli/docker/mcp/profile/server/ls Use this command to display all servers across all defined profiles. No specific setup is required beyond having Docker MCP installed and configured. ```bash docker mcp profile server ls ``` -------------------------------- ### Define proxy and backend services with build and volumes Source: https://docs.docker.com/reference/compose-file/services This example shows how to configure a proxy service with a mounted configuration file and a backend service that builds its image from a Dockerfile. ```yaml services: proxy: image: nginx volumes: - type: bind source: ./proxy/nginx.conf target: /etc/nginx/conf.d/default.conf read_only: true ports: - 80:80 depends_on: - backend backend: build: context: backend target: builder ``` -------------------------------- ### Get system memory info with process isolation Source: https://docs.docker.com/reference/cli/docker/container/run When using process isolation on Windows, applications inside the container report the full host system memory. This example queries memory information. ```powershell PS C:\> docker run -it -m 2GB --isolation=process microsoft/nanoserver powershell Get-ComputerInfo *memory* ``` -------------------------------- ### Create and Run Kiro Sandbox Source: https://docs.docker.com/reference/cli/docker/sandbox/create/kiro This example demonstrates creating a named Kiro sandbox with a specified workspace and then immediately running 'kiro' within that sandbox. Additional workspaces can be mounted, with ':ro' suffix for read-only access. ```console $ docker sandbox create --name my-kiro kiro ~/my-project $ docker sandbox run my-kiro ``` -------------------------------- ### Get Container Exit Code with Docker Attach Source: https://docs.docker.com/reference/cli/docker/container/attach This example demonstrates how to retrieve the exit code of a container's command using `docker attach`. The exit code of the process inside the container is returned by the `docker attach` command. ```console $ docker run --name test -dit alpine 275c44472aebd77c926d4527885bb09f2f6db21d878c75f0a1c212c03d3bcfab $ docker attach test /# exit 13 $ echo $? 13 $ docker ps -a --filter name=test CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a2fe3fd886db alpine "/bin/sh" About a minute ago Exited (13) 40 seconds ago test ``` -------------------------------- ### Get system memory info with Hyper-V isolation Source: https://docs.docker.com/reference/cli/docker/container/run With Hyper-V isolation on Windows, the reported 'Total Physical Memory' reflects the size of the utility VM created for the container, which includes the memory limit plus the OS overhead. This example queries memory information. ```powershell PS C:\> docker run -it -m 2GB --isolation=hyperv microsoft/nanoserver powershell Get-ComputerInfo *memory* ``` -------------------------------- ### HTTP Methods - GET Source: https://docs.docker.com/reference/api/extensions-sdk/BackendV0 Performs an HTTP GET request to a backend service. This method will be removed in a future version. Use [get](/reference/api/extensions-sdk/BackendV0/HttpService/#get) instead. ```APIDOC ## GET /get ### Description Performs an HTTP GET request to a backend service. ### Method GET ### Endpoint /get ### Parameters #### Query Parameters - **url** (string) - Required - The URL of the backend service. ### Request Example ```json { "url": "/some/service" } ``` ### Response #### Success Response (200) - **data** (unknown) - The response data from the backend service. #### Response Example ```json { "data": "some response data" } ``` ``` -------------------------------- ### Create and list services Source: https://docs.docker.com/reference/cli/docker/service/create Demonstrates creating replicated and global services and listing them to verify status. ```console $ docker service create --name redis redis:7.4.1 dmu1ept4cxcfe8k8lhtux3ro3 $ docker service create --mode global --name redis2 redis:7.4.1 a8q9dasaafudfs8q8w32udass $ docker service ls ID NAME MODE REPLICAS IMAGE dmu1ept4cxcf redis replicated 1/1 redis:7.4.1 a8q9dasaafud redis2 global 1/1 redis:7.4.1 ``` -------------------------------- ### Install Docker Model Skills for OpenCode Source: https://docs.docker.com/reference/cli/docker/model/skills Use this command to install skills for OpenCode. The skills will be installed to the default location: ~/.config/opencode/skills. ```bash docker model skills --opencode ``` -------------------------------- ### Run a container with Go SDK Source: https://docs.docker.com/reference/api/engine/sdk This Go code demonstrates pulling an image, creating a container, starting it, waiting for it to complete, and retrieving its logs using the Docker SDK. Ensure the Docker environment is accessible. ```go package main import ( "context" "io" "os" "github.com/moby/moby/api/pkg/stdcopy" "github.com/moby/moby/api/types/container" "github.com/moby/moby/client" ) func main() { ctx := context.Background() apiClient, err := client.New(client.FromEnv) if err != nil { panic(err) } defer apiClient.Close() reader, err := apiClient.ImagePull(ctx, "docker.io/library/alpine", client.ImagePullOptions{}) if err != nil { panic(err) } io.Copy(os.Stdout, reader) resp, err := apiClient.ContainerCreate(ctx, client.ContainerCreateOptions{ Image: "alpine", Config: &container.Config{ Cmd: []string{"echo", "hello world"}, }, }) if err != nil { panic(err) } if _, err := apiClient.ContainerStart(ctx, resp.ID, client.ContainerStartOptions{}); err != nil { panic(err) } wait := apiClient.ContainerWait(ctx, resp.ID, client.ContainerWaitOptions{}) select { case err := <-wait.Error: if err != nil { panic(err) } case <-wait.Result: } out, err := apiClient.ContainerLogs(ctx, resp.ID, client.ContainerLogsOptions{ShowStdout: true}) if err != nil { panic(err) } stdcopy.StdCopy(os.Stdout, os.Stderr, out) } ``` -------------------------------- ### Install Docker Model Skills for Claude Source: https://docs.docker.com/reference/cli/docker/model/skills Use this command to install skills for Claude Code. The skills will be installed to the default location: ~/.claude/skills. ```bash docker model skills --claude ``` -------------------------------- ### Connect to a network with sysctl settings and static IP using extended syntax Source: https://docs.docker.com/reference/cli/docker/run This example demonstrates using the extended --network syntax to configure network interface sysctl settings and assign a static IP address simultaneously. Ensure proper shell escaping for the driver-opt field. ```bash $ docker network create --subnet 192.0.2.0/24 my-net $ docker run -itd --network=name=my-net,"driver-opt=com.docker.network.endpoint.sysctls=net.ipv4.conf.IFNAME.log_martians=1,net.ipv4.conf.IFNAME.forwarding=0",ip=192.0.2.42 busybox ``` -------------------------------- ### Install Docker Model Skills for Codex Source: https://docs.docker.com/reference/cli/docker/model/skills Use this command to install skills for OpenAI Codex CLI. The skills will be installed to the default location: ~/.codex/skills. ```bash docker model skills --codex ``` -------------------------------- ### Create and List Volumes Source: https://docs.docker.com/reference/cli/docker/volume/ls Demonstrates creating two volumes and then listing all volumes to show them. ```console $ docker volume create rosemary rosemary $ docker volume create tyler tyler $ docker volume ls DRIVER VOLUME NAME local rosemary local tyler ``` -------------------------------- ### Install Python SDK using pip Source: https://docs.docker.com/reference/api/engine/sdk The recommended way to install the Python SDK for Docker is using pip. This command installs the latest version. ```bash pip install docker ``` -------------------------------- ### List installed plugins Source: https://docs.docker.com/reference/cli/docker/plugin/install Lists all installed plugins, showing their ID, name, description, and enabled status. This command is used to verify that a plugin has been successfully installed. ```console $ docker plugin ls ID NAME DESCRIPTION ENABLED 69553ca1d123 vieux/sshfs:latest sshFS plugin for Docker true ``` -------------------------------- ### Connect to BuildKit via dial-stdio in Go Source: https://docs.docker.com/reference/cli/docker/buildx/dial-stdio This example demonstrates how to use the dial-stdio command to establish a connection to a BuildKit client using a custom context dialer. ```go client.New(ctx, "", client.WithContextDialer(func(context.Context, string) (net.Conn, error) { c1, c2 := net.Pipe() cmd := exec.Command("docker", "buildx", "dial-stdio") cmd.Stdin = c1 cmd.Stdout = c1 if err := cmd.Start(); err != nil { c1.Close() c2.Close() return nil, err } go func() { cmd.Wait() c2.Close() }() return c2 })) ``` -------------------------------- ### docker compose start Source: https://docs.docker.com/reference/cli/docker/compose/start Starts existing containers for a service. ```APIDOC ## docker compose start ### Description Starts existing containers for a service. ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Options - **--wait** (boolean) - Optional - Wait for services to be running healthy. Implies detached mode. - **--wait-timeout** (duration) - Optional - Maximum duration in seconds to wait for the project to be running healthy. ### Usage `docker compose start [SERVICE...]` ### Request Example ```bash docker compose start web docker compose start web backend ``` ### Response #### Success Response (0) Indicates that the services were started successfully. #### Response Example ``` [Output indicating services are starting or running] ``` ``` -------------------------------- ### Create manifest list Source: https://docs.docker.com/reference/cli/docker/manifest Initialize a manifest list locally by specifying the constituent images. ```console $ docker manifest create 45.55.81.106:5000/coolapp:v1 \ 45.55.81.106:5000/coolapp-ppc64le-linux:v1 \ 45.55.81.106:5000/coolapp-arm-linux:v1 \ 45.55.81.106:5000/coolapp-amd64-linux:v1 \ 45.55.81.106:5000/coolapp-amd64-windows:v1 Created manifest list 45.55.81.106:5000/coolapp:v1 ``` -------------------------------- ### POST /plugin/install Source: https://docs.docker.com/reference/cli/docker/plugin/install Installs and enables a plugin from a registry or local host. ```APIDOC ## POST /plugin/install ### Description Installs and enables a plugin. Docker looks first for the plugin on your Docker host. If the plugin does not exist locally, then the plugin is pulled from the registry. ### Method POST ### Endpoint docker plugin install [OPTIONS] PLUGIN [KEY=VALUE...] ### Parameters #### Path Parameters - **PLUGIN** (string) - Required - The name of the plugin to install. #### Query Parameters - **--alias** (string) - Optional - Local name for plugin. - **--disable** (boolean) - Optional - Do not enable the plugin on install. - **--grant-all-permissions** (boolean) - Optional - Grant all permissions necessary to run the plugin. ### Request Example $ docker plugin install vieux/sshfs DEBUG=1 ### Response #### Success Response (200) - **Plugin Name** (string) - The name of the successfully installed plugin. ``` -------------------------------- ### GET /version Source: https://docs.docker.com/reference/api/engine/version-history The GET /version endpoint now returns the MinAPIVersion field. ```APIDOC ## GET /version ### Description Retrieves the current Docker API version information. This endpoint now includes the `MinAPIVersion` field in its response. ### Method GET ### Endpoint `/version` ### Response #### Success Response (200) - **MinAPIVersion** (string) - The minimum API version supported by the server. - **ApiVersion** (string) - The current API version of the server. ``` -------------------------------- ### Initialize an ASP.NET Core project with docker init Source: https://docs.docker.com/reference/cli/docker/init Prompts and output for configuring an ASP.NET Core application. ```console ? What application platform does your project use? ASP.NET Core ? What's the name of your solution's main project? myapp ? What version of .NET do you want to use? 6.0 ? What local port do you want to use to access your server? 8000 CREATED: .dockerignore CREATED: Dockerfile CREATED: compose.yaml CREATED: README.Docker.md ✔ Your Docker files are ready! Take a moment to review them and tailor them to your application. When you're ready, start your application by running: docker compose up --build Your application will be available at http://localhost:8000 Consult README.Docker.md for more information about using the generated files. ``` -------------------------------- ### GET /info Source: https://docs.docker.com/reference/api/engine/version-history The `KernelMemoryTCP` field has been removed from the GET /info endpoint. ```APIDOC ## GET /info ### Description Returns system-wide information of the Docker host. ### Method GET ### Endpoint /info ### Response #### Success Response (200) - **KernelMemoryTCP** (integer) - Removed. ``` -------------------------------- ### Initialize and share volumes Source: https://docs.docker.com/reference/cli/docker/container/create Demonstrates initializing a volume container and mounting it into another container using the --volumes-from flag. ```console $ docker create -v /data --name data ubuntu 240633dfbb98128fa77473d3d9018f6123b99c454b3251427ae190a7d951ad57 $ docker run --rm --volumes-from data ubuntu ls -la /data total 8 drwxr-xr-x 2 root root 4096 Dec 5 04:10 . drwxr-xr-x 48 root root 4096 Dec 5 04:11 .. ``` ```console $ docker create -v /home/docker:/docker --name docker ubuntu 9aa88c08f319cd1e4515c3c46b0de7cc9aa75e878357b1e96f91e2c773029f03 $ docker run --rm --volumes-from docker ubuntu ls -la /docker total 20 drwxr-sr-x 5 1000 staff 180 Dec 5 04:00 . drwxr-xr-x 48 root root 4096 Dec 5 04:13 .. -rw-rw-r-- 1 1000 staff 3833 Dec 5 04:01 .ash_history -rw-r--r-- 1 1000 staff 446 Nov 28 11:51 .ashrc -rw-r--r-- 1 1000 staff 25 Dec 5 04:00 .gitconfig drwxr-sr-x 3 1000 staff 60 Dec 1 03:28 .local -rw-r--r-- 1 1000 staff 920 Nov 28 11:51 .profile drwx--S--- 2 1000 staff 460 Dec 5 00:51 .ssh drwxr-xr-x 32 1000 staff 1140 Dec 5 04:01 docker ``` -------------------------------- ### Docker Plugin Install Source: https://docs.docker.com/reference/cli/docker/plugin Installs a Docker plugin from a registry or a local source. ```APIDOC ## docker plugin install ### Description Install a plugin ### Method Not applicable (CLI command) ### Endpoint Not applicable (CLI command) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash docker plugin install [OPTIONS] PLUGIN [PLUGIN...] ``` ### Response None (CLI output) ``` -------------------------------- ### JSON output example Source: https://docs.docker.com/reference/cli/docker/trust/inspect Example of the JSON structure returned by the inspect command. ```json [ { "Name": "alpine", "SignedTags": [ { "SignedTag": "3.5", "Digest": "b007a354427e1880de9cdba533e8e57382b7f2853a68a478a17d447b302c219c", "Signers": [ "Repo Admin" ] }, { "SignedTag": "3.6", "Digest": "d6bfc3baf615dc9618209a8d607ba2a8103d9c8a405b3bd8741d88b4bef36478", "Signers": [ "Repo Admin" ] }, { "SignedTag": "edge", "Digest": "23e7d843e63a3eee29b6b8cfcd10e23dd1ef28f47251a985606a31040bf8e096", "Signers": [ "Repo Admin" ] }, { "SignedTag": "latest", "Digest": "d6bfc3baf615dc9618209a8d607ba2a8103d9c8a405b3bd8741d88b4bef36478", "Signers": [ "Repo Admin" ] } ], "Signers": [], "AdministrativeKeys": [ { "Name": "Repository", "Keys": [ { "ID": "5a46c9aaa82ff150bb7305a2d17d0c521c2d784246807b2dc611f436a69041fd" } ] }, { "Name": "Root", "Keys": [ { "ID": "a2489bcac7a79aa67b19b96c4a3bf0c675ffdf00c6d2fabe1a5df1115e80adce" } ] } ] } ] ``` ```json [ { "Name": "alpine", "SignedTags": [ { "SignedTag": "3.5", "Digest": "b007a354427e1880de9cdba533e8e57382b7f2853a68a478a17d447b302c219c", "Signers": [ "Repo Admin" ] }, { "SignedTag": "3.6", "Digest": "d6bfc3baf615dc9618209a8d607ba2a8103d9c8a405b3bd8741d88b4bef36478", "Signers": [ "Repo Admin" ] }, { "SignedTag": "edge", "Digest": "23e7d843e63a3eee29b6b8cfcd10e23dd1ef28f47251a985606a31040bf8e096", "Signers": [ "Repo Admin" ] }, { "SignedTag": "integ-test-base", "Digest": "3952dc48dcc4136ccdde37fbef7e250346538a55a0366e3fccc683336377e372", "Signers": [ "Repo Admin" ] }, { "SignedTag": "latest", "Digest": "d6bfc3baf615dc9618209a8d607ba2a8103d9c8a405b3bd8741d88b4bef36478", "Signers": [ "Repo Admin" ] } ], "Signers": [], "AdministrativeKeys": [ { "Name": "Repository", "Keys": [ { "ID": "5a46c9aaa82ff150bb7305a2d17d0c521c2d784246807b2dc611f436a69041fd" } ] }, { "Name": "Root", "Keys": [ { "ID": "a2489bcac7a79aa67b19b96c4a3bf0c675ffdf00c6d2fabe1a5df1115e80adce" } ] } ] }, { "Name": "notary", "SignedTags": [ { "SignedTag": "server", "Digest": "71f64ab718a3331dee103bc5afc6bc492914738ce37c2d2f127a8133714ecf5c", "Signers": [ "Repo Admin" ] }, { "SignedTag": "signer", "Digest": "a6122d79b1e74f70b5dd933b18a6d1f99329a4728011079f06b245205f158fe8", "Signers": [ "Repo Admin" ] } ], "Signers": [], "AdministrativeKeys": [ { "Name": "Root", "Keys": [ { "ID": "8cdcdef5bd039f4ab5a029126951b5985eebf57cabdcdc4d21f5b3be8bb4ce92" } ] }, { "Name": "Repository", "Keys": [ { "ID": "85bfd031017722f950d480a721f845a2944db26a3dc084040a70f1b0d9bbb3df" } ] } ] } ] ```