Skip to content

Commit 6d65bae

Browse files
authored
Update documentation for container, exec and service (#1293)
* Update documentation for container, exec and service Signed-off-by: Dan Webb <dan.webb@damacus.io> * Update readme, and documentation folder Signed-off-by: Dan Webb <dan.webb@damacus.io> * Update readme, and documentation folder Signed-off-by: Dan Webb <dan.webb@damacus.io> * Fix default_script_url Signed-off-by: Dan Webb <dan.webb@damacus.io> --------- Signed-off-by: Dan Webb <dan.webb@damacus.io>
1 parent 88b8652 commit 6d65bae

12 files changed

+905
-194
lines changed

CHANGELOG.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- Update documentation for `docker_container` resource
11+
- Update documentation for `docker_service` resource
12+
- Update documentation for `docker_exec` resource
13+
- Update resources overview
14+
- Update documentation for `docker_installation_package` resource
15+
- Update documentation for `docker_installation_script` resource
16+
- Update documentation for `docker_installation_tarball` resource
17+
- Update documentation for `docker_service_manager_execute` resource
18+
- Update documentation for `docker_service_manager_systemd` resource
19+
- Update documentation for `docker_volume_prune` resource
20+
<<<<<<< HEAD
21+
1022
## 11.8.3 - *2024-12-11*
1123

1224
- Cleanup changelog
25+
=======
26+
27+
>>>>>>> 5326caf (Update readme, and documentation folder)
1328
1429
## 11.8.2 - *2024-12-11*
1530

@@ -808,6 +823,3 @@ The 7.0 release includes a breaking change to package installs with version spec
808823
- [#296](https://github.com/sous-chefs/docker/issues/296)
809824
- [#297](https://github.com/sous-chefs/docker/issues/297)
810825
- [#298](https://github.com/sous-chefs/docker/issues/298)
811-
812-
[@jcrobak]: https://github.com/jcrobak
813-
[@wingrunr21]: https://github.com/wingrunr21

README.md

+12-10
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,21 @@ Those recipes are found at `test/cookbooks/docker_test`.
7373
## Resources Overview
7474

7575
- [docker_service](documentation/docker_service.md): composite resource that uses docker_installation and docker_service_manager
76-
- [docker_installation](#docker_installation): automatically select an installation method
77-
- [docker_service_manager](#docker_service_manager): automatically selects a service manager
78-
- [docker_installation_script](#docker_installation_script): curl | bash
79-
- [docker_installation_package](#docker_installation_package): package 'docker-ce'
80-
- [docker_service_manager_execute](#docker_service_manager_execute): manage docker daemon with Chef
81-
- [docker_service_manager_systemd](#docker_service_manager_systemd): manage docker daemon with systemd unit files
82-
- [docker_image](documentation/docker_image.md): image/repository operations
8376
- [docker_container](documentation/docker_container.md): container operations
84-
- [docker_tag](documentation/docker_tag.md): image tagging operations
85-
- [docker_registry](documentation/docker_registry.md): registry operations
77+
- [docker_exec](documentation/docker_exec.md): execute commands inside running containers
78+
- [docker_image](documentation/docker_image.md): image/repository operations
79+
- [docker_image_prune](documentation/docker_image_prune.md): remove unused docker images
80+
- [docker_installation_package](documentation/docker_installation_package.md): install Docker via package 'docker-ce'
81+
- [docker_installation_script](documentation/docker_installation_script.md): install Docker via curl | bash
82+
- [docker_installation_tarball](documentation/docker_installation_tarball.md): install Docker from a tarball
8683
- [docker_network](documentation/docker_network.md): network operations
87-
- [docker_volume](documentation/docker_volume.md): volume operations
8884
- [docker_plugin](documentation/docker_plugin.md): plugin operations
85+
- [docker_registry](documentation/docker_registry.md): registry operations
86+
- [docker_service_manager_execute](documentation/docker_service_manager_execute.md): manage docker daemon with Chef
87+
- [docker_service_manager_systemd](documentation/docker_service_manager_systemd.md): manage docker daemon with systemd unit files
88+
- [docker_tag](documentation/docker_tag.md): image tagging operations
89+
- [docker_volume](documentation/docker_volume.md): volume operations
90+
- [docker_volume_prune](documentation/docker_volume_prune.md): remove unused docker volumes
8991

9092
## Getting Started
9193

documentation/docker_container.md

+146-66
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# docker_container
22

3-
The `docker_container` is responsible for managing Docker container actions. It speaks directly to the [Docker remote API](https://docs.docker.com/reference/api/docker_remote_api_v1.20/).
3+
The `docker_container` resource is responsible for managing Docker container actions. It speaks directly to the [Docker remote API](https://docs.docker.com/reference/api/docker_remote_api_v1.20/).
44

5-
Containers are process oriented, and move through an event cycle.
5+
Containers are process oriented and move through an event cycle.
66

77
## Actions
88

99
- `:create` - Creates the container but does not start it. Useful for Volume containers.
10-
- `:start` - Starts the container. Useful for containers that run jobs.. command that exit.
10+
- `:start` - Starts the container. Useful for containers that run jobs and exit.
1111
- `:run` - The default action. Both `:create` and `:start` the container in one action. Redeploys the container on resource change.
1212
- `:run_if_missing` - Runs a container only once.
1313
- `:stop` - Stops the container.
@@ -23,82 +23,135 @@ Containers are process oriented, and move through an event cycle.
2323

2424
Most `docker_container` properties are the `snake_case` version of the `CamelCase` keys found in the [Docker Remote Api](https://docs.docker.com/reference/api/docker_remote_api_v1.20/)
2525

26+
### Core Properties
27+
2628
- `container_name` - The name of the container. Defaults to the name of the `docker_container` resource.
2729
- `repo` - aka `image_name`. The first half of a the complete identifier for a Docker Image.
28-
- `tag` - The second half of a Docker image's identity. - Defaults to `latest`.
30+
- `tag` - The second half of a Docker image's identity. Defaults to `latest`.
2931
- `command` - The command to run when starting the container.
30-
- `autoremove` - Boolean - Automatically delete a container when it's command exits. Defaults to `false`.
31-
- `volumes` - An array of volume bindings for this container. Each volume binding is a string in one of these forms: `container_path` to create a new volume for the container. `host_path:container_path` to bind-mount a host path into the container. `host_path:container_path:ro` to make the bind-mount read-only inside the container.
32-
- `cap_add` - An array Linux Capabilities (`man 7 capabilities`) to add to grant the container beyond what it normally gets.
33-
- `cap_drop` - An array Linux Capabilities (`man 7 capabilities`) to revoke that the container normally has.
32+
- `working_dir` - A string specifying the working directory for commands to run in.
33+
- `user` - A string value specifying the user inside the container.
34+
35+
### Resource Management
36+
3437
- `cpus` - A float or integer value specifying how much of the available CPU resources a container can use. Available in Docker 1.13 and higher.
3538
- `cpu_shares` - An integer value containing the CPU Shares for the container.
36-
- `devices` - A Hash of devices to add to the container.
37-
- `dns` - An array of DNS servers the container will use for name resolution.
38-
- `dns_search` - An array of domains the container will search for name resolution.
39-
- `domain_name` - Set's the container's dnsdomainname as returned by the `dnsdomainname` command.
40-
- `entrypoint` - Set the entry point for the container as a string or an array of strings.
41-
- `env` - Set environment variables in the container in the form `['FOO=bar', 'BIZ=baz']`
42-
- `env_file` - Read environment variables from a file and set in the container. Accepts an Array or String to the file location. lazy evaluator must be set if the file passed is created by Chef.
43-
- `extra_hosts` - An array of hosts to add to the container's `/etc/hosts` in the form `['host_a:10.9.8.7', 'host_b:10.9.8.6']`
44-
- `force` - A boolean to use in container operations that support a `force` option. Defaults to `false`
45-
- `gpus` - GPU devices to add to the container. Use 'all' to pass all GPUs to the container.
46-
- `gpu_driver` - GPU driver to use for container. Defaults to 'nvidia'.
47-
- `health_check` - A hash containing the health check options - [healthcheck reference](https://docs.docker.com/engine/reference/run/#healthcheck)
48-
- `host` - A string containing the host the API should communicate with. Defaults to ENV['DOCKER_HOST'] if set
49-
- `host_name` - The hostname for the container.
50-
- `labels` A string, array, or hash to set metadata on the container in the form `['foo:bar', 'hello:world']`
51-
- `links` - An array of source container/alias pairs to link the container to in the form `[container_a:www', container_b:db']`
52-
- `log_driver` - Sets a custom logging driver for the container (json-file/syslog/journald/gelf/fluentd/awslogs/splunk/etwlogs/gcplogs/logentries/loki-docker/local/none).
53-
- `log_opts` - Configures the above logging driver options (driver-specific).
54-
- `init` - Run an init inside the container that forwards signals and reaps processes.
55-
- `ip_address` - Container IPv4 address (e.g. 172.30.100.104)
56-
- `mac_address` - The mac address for the container to use.
5739
- `memory` - Memory limit in bytes.
58-
- `memory_swap` - Total memory limit (memory + swap); set `-1` to disable swap limit (unlimited). You must use this with memory and make the swap value larger than memory.
40+
- `memory_swap` - Total memory limit (memory + swap); set `-1` to disable swap limit (unlimited). Must be used with memory and set larger than memory.
41+
- `shm_size` - The size of `/dev/shm`. Format is `<number><unit>`, where number must be greater than 0. Unit is optional: b (bytes), k (kilobytes), m (megabytes), or g (gigabytes). Default is `64m`.
42+
43+
### Storage and Volumes
44+
45+
- `volumes` - An array of volume bindings for this container. Each binding can be:
46+
- `container_path` - Creates a new volume for the container
47+
- `host_path:container_path` - Bind-mounts a host path into the container
48+
- `host_path:container_path:ro` - Makes the bind-mount read-only inside the container
49+
- `volumes_from` - A list of volumes to inherit from another container. Format: `<container name>[:<ro|rw>]`
50+
- `volume_driver` - Driver that this container uses to mount volumes.
51+
- `tmpfs` - A hash or array of tmpfs mounts to add to the container. Provides temporary filesystem without requiring privileged mode.
52+
53+
### Networking
54+
55+
- `network_mode` - Sets the networking mode for the container. One of:
56+
- `bridge` - Default Docker bridge network
57+
- `host` - Use the host's network stack inside the container
58+
- `container:<name|id>` - Use another container's network stack
59+
- `none` - No networking
5960
- `network_disabled` - Boolean to disable networking. Defaults to `false`.
60-
- `network_mode` - Sets the networking mode for the container. One of `bridge`, `host`, `container`.
6161
- `network_aliases` - Adds network-scoped alias for the container in form `['alias-1', 'alias-2']`.
62-
- `oom_kill_disable` - Whether to disable OOM Killer for the container or not.
63-
- `oom_score_adj` - Tune container's OOM preferences (-1000 to 1000).
64-
- `open_stdin` - Boolean value, opens stdin. Defaults to `false`.
65-
- `outfile` - The path to write the file when using `:export` action.
66-
- `port` - The port configuration to use in the container. Matches the syntax used by the `docker` CLI tool.
67-
- `privileged` - Boolean to start the container in privileged more. Defaults to `false`
68-
- `publish_all_ports` - Allocates a random host port for all of a container's exposed ports.
69-
- `remove_volumes` - A boolean to clean up "dangling" volumes when removing the last container with a reference to it. Default to `false` to match the Docker CLI behavior.
70-
- `restart_policy` - One of `no`, `on-failure`, `unless-stopped`, or `always`. Use `always` if you want a service container to survive a Dockerhost reboot. Defaults to `no`.
71-
- `restart_maximum_retry_count` - Maximum number of restarts to try when `restart_policy` is `on-failure`. Defaults to an ever increasing delay (double the previous delay, starting at 100mS), to prevent flooding the server.
72-
- `running_wait_time` - Amount of seconds `docker_container` wait to determine if a process is running.
73-
- `runtime` - Runtime to use when running container. Defaults to `runc`.
62+
- `hostname` - The hostname for the container.
63+
- `domain_name` - Sets the container's dnsdomainname as returned by the `dnsdomainname` command.
64+
- `dns` - An array of DNS servers the container will use for name resolution.
65+
- `dns_search` - An array of domains the container will search for name resolution.
66+
- `mac_address` - The mac address for the container to use.
67+
- `ip_address` - Container IPv4 address (e.g. 172.30.100.104)
68+
69+
### Security and Resource Constraints
70+
71+
- `privileged` - Boolean to start the container in privileged mode. Defaults to `false`.
72+
- `cap_add` - An array Linux Capabilities (`man 7 capabilities`) to add to grant the container beyond what it normally gets.
73+
- `cap_drop` - An array Linux Capabilities (`man 7 capabilities`) to revoke that the container normally has.
7474
- `security_opt` - A list of string values to customize labels for MLS systems, such as SELinux.
75-
- `shm_size` - The size of `/dev/shm`. The format is `<number><unit>`, where number must be greater than 0. Unit is optional and can be b (bytes), k (kilobytes), m(megabytes), or g (gigabytes). The default is `64m`.
76-
- `signal` - The signal to send when using the `:kill` action. Defaults to `SIGTERM`.
77-
- `sysctls` - A hash of sysctl settings to configure for the container.
78-
- `timeout` - Timeout setting for container operations.
79-
- `tmpfs` - A hash or array of tmpfs mounts to add to the container. Useful for providing a temporary filesystem without requiring privileged mode.
80-
- `tty` - Boolean value, allocates a pseudo-TTY. Defaults to `false`.
81-
- `user` - A string value specifying the user inside the container.
82-
- `volumes` - An Array of paths inside the container to expose. Does the same thing as the `VOLUME` directive in a Dockerfile, but works on container creation.
83-
- `volumes_from` - A list of volumes to inherit from another container. Specified in the form `<container name>[:<ro|rw>]`
84-
- `volume_driver` - Driver that this container users to mount volumes.
85-
- `working_dir` - A string specifying the working directory for commands to run in.
86-
- `read_timeout` - May need to increase for commits or exports that are slow
87-
- `write_timeout` - May need to increase for commits or exports that are slow
88-
- `kill_after` - Number of seconds to wait before killing the container. Defaults to wait indefinitely; eventually will hit read_timeout limit.
89-
- `tls` - Use TLS; implied by --tlsverify. Defaults to ENV['DOCKER_TLS'] if set
90-
- `tls_verify` - Use TLS and verify the remote. Defaults to ENV['DOCKER_TLS_VERIFY'] if set
91-
- `tls_ca_cert` - Trust certs signed only by this CA. Defaults to ENV['DOCKER_CERT_PATH'] if set
92-
- `tls_client_cert` - Path to TLS certificate file for docker cli. Defaults to ENV['DOCKER_CERT_PATH'] if set
93-
- `tls_client_key` - Path to TLS key file for docker cli. Defaults to ENV['DOCKER_CERT_PATH'] if set
94-
- `userns_mode` - Modify the user namespace mode - Defaults to `nil`, example option: `host`
75+
- `userns_mode` - Modify the user namespace mode. Defaults to `nil`, example option: `host`
9576
- `pid_mode` - Set the PID (Process) Namespace mode for the container. `host`: use the host's PID namespace inside the container.
96-
- `ipc_mode` - Set the IPC mode for the container - Defaults to `nil`, example option: `host`
97-
- `uts_mode` - Set the UTS namespace mode for the container. The UTS namespace is for setting the hostname and the domain that is visible to running processes in that namespace. By default, all containers, including those with `--network=host`, have their own UTS namespace. The host setting will result in the container using the same UTS namespace as the host. Note that --hostname is invalid in host UTS mode.
98-
- `ro_rootfs` - Mount the container's root filesystem as read only using the `--read-only` flag. Defaults to `false`
77+
- `ipc_mode` - Set the IPC mode for the container. Defaults to `nil`, example option: `host`
78+
- `uts_mode` - Set the UTS namespace mode for the container.
79+
- `ro_rootfs` - Mount the container's root filesystem as read only. Defaults to `false`
80+
81+
### Logging Properties
82+
83+
- `log_driver` - The logging driver to use for the container. One of:
84+
- `json-file` - Default Docker logging driver that writes JSON messages to file
85+
- `syslog` - Syslog logging driver that writes log messages to syslog
86+
- `journald` - Journald logging driver that writes log messages to systemd journal
87+
- `gelf` - Graylog Extended Log Format (GELF) logging driver
88+
- `fluentd` - Fluentd logging driver
89+
- `awslogs` - Amazon CloudWatch Logs logging driver
90+
- `splunk` - Splunk logging driver
91+
- `etwlogs` - ETW logging driver for Windows
92+
- `gcplogs` - Google Cloud Logging driver
93+
- `logentries` - Logentries logging driver
94+
- `loki-docker` - Grafana Loki logging driver
95+
- `none` - Disables container logging
96+
- `local` - Local file-based logging driver
97+
Defaults to `json-file`.
98+
99+
- `log_opts` - A hash of key-value pairs to configure the selected log driver. Common options include:
100+
- For json-file:
101+
- `max-size` - Maximum size of the log before it is rolled
102+
- `max-file` - Maximum number of log files that can exist
103+
- For syslog:
104+
- `syslog-address` - Address of remote syslog server
105+
- `tag` - Tag for syslog messages
106+
- For other drivers, refer to the [Docker logging configuration documentation](https://docs.docker.com/config/containers/logging/configure/)
107+
108+
### GPU Support
109+
110+
- `gpus` - GPU devices to add to the container. Use 'all' to pass all GPUs.
111+
- `gpu_driver` - GPU driver to use. Defaults to 'nvidia'.
99112

100113
## Examples
101114

115+
### Basic Container Creation
116+
117+
```ruby
118+
docker_container 'hello-world' do
119+
command '/hello'
120+
action :create
121+
end
122+
```
123+
124+
### Using tmpfs Mounts
125+
126+
```ruby
127+
# Using hash format with mount options
128+
docker_container 'tmpfs_test' do
129+
repo 'nginx'
130+
tmpfs({
131+
'/tmpfs1' => '', # No options
132+
'/tmpfs2' => 'size=20M,uid=1000', # With size and uid options
133+
'/tmpfs3' => 'rw,noexec,nosuid,size=50M' # With multiple options
134+
})
135+
end
136+
137+
# Using array format (all mounts will have default options)
138+
docker_container 'tmpfs_test' do
139+
repo 'nginx'
140+
tmpfs ['/tmpfs1', '/tmpfs2']
141+
end
142+
```
143+
144+
### Container with GPU Support
145+
146+
```ruby
147+
docker_container 'gpu_container' do
148+
repo 'nvidia/cuda'
149+
tag 'latest'
150+
gpus 'all' # Pass all GPUs to the container
151+
gpu_driver 'nvidia' # Use NVIDIA driver
152+
end
153+
```
154+
102155
### Create a container without starting it
103156

104157
```ruby
@@ -564,3 +617,30 @@ docker_container 'custom_gpu_container' do
564617
gpu_driver 'custom_driver'
565618
action :run_if_missing
566619
end
620+
621+
```
622+
623+
### Using json-file driver with size limits
624+
625+
```ruby
626+
docker_container 'webapp' do
627+
repo 'nginx'
628+
log_driver 'json-file'
629+
log_opts({
630+
'max-size' => '10m',
631+
'max-file' => '3'
632+
})
633+
end
634+
```
635+
636+
### Using syslog driver with remote server
637+
638+
```ruby
639+
docker_container 'webapp' do
640+
repo 'nginx'
641+
log_driver 'syslog'
642+
log_opts({
643+
'syslog-address' => 'udp://1.2.3.4:1111',
644+
'tag' => 'webapp'
645+
})
646+
end

0 commit comments

Comments
 (0)