FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

125 snippets foundClear filters
Docker / ComposeContainer commands

Read a field from container metadata

Use an inspect template for stable machine-readable output.

inspect✓ Tested
Docker / ComposeCompose service options

Read a secret from a mounted file

Docker / Compose: Compose secrets make a file available under /run/secrets.

Docker / Compose✓ Tested
Docker / ComposeImage management

Read an image’s default command

Docker / Compose: Config.Cmd contains the command arguments stored in the image.

Docker / Compose✓ Tested
Docker / ComposeContainer commands

Read output from a completed container

Retrieve the stdout captured by Docker.

logs✓ Tested
Docker / ComposeNetworks & volume metadata

Remove one network attachment

Docker / Compose: network disconnect removes the specified attachment while retaining the container.

Docker / Compose✓ Tested
Docker / ComposeImage management

Remove one tag while retaining another reference

Docker / Compose: Removing a tag does not delete an image still referenced by another tag.

Docker / Compose✓ Tested
Docker / ComposeContainer lifecycle

Rename a container without recreating it

Docker / Compose: rename updates the container name while preserving its identity.

Docker / Compose✓ Tested
Docker / ComposeImage management

Require a locally available image

Docker / Compose: The never pull policy fails for missing images instead of attempting a download.

Docker / Compose✓ Tested
Docker / ComposeNetworks & volume metadata

Resolve a peer’s name on a user-defined network

Docker / Compose: The embedded DNS service resolves names on user-defined bridges.

Docker / Compose✓ Tested
Docker / ComposeContainer lifecycle

Restart an existing container

Docker / Compose: restart starts the same container again while retaining its writable layer.

Docker / Compose✓ Tested
Docker / ComposeExecution & file transfer

Retrieve a file from a stopped container

Docker / Compose: The writable layer remains available for docker cp after exit.

Docker / Compose✓ Tested
Docker / ComposeContainer commands

Run a command in a running container

Execute an additional process inside an existing container.

exec✓ Tested