Skip to content

Commit d7c1436

Browse files
committed
update docker docs
1 parent ed6e954 commit d7c1436

File tree

2 files changed

+21
-104
lines changed
  • docs
    • advanced/7_docker
    • getting_started/0_scripts_quickstart/7_docker_quickstart

2 files changed

+21
-104
lines changed

docs/advanced/7_docker/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ Here an example of a a worker group setup with a dind side-container to be adapt
8080
## Using Windmill native docker support (recommended)
8181

8282
Windmill has a native docker support if the `# docker` annotation is used. It will assume a a docker socket is mounted like in the example above and will take over management of the container as soon as the script ends, assuming that the container was ran with the `$WM_JOB_ID` as name.
83-
Which is why you should use docker `-d` deamon mode so that the bash script terminates early.
83+
Which is why you should use docker `-d` deamon mode so that the bash script terminates early.
8484

85-
It will handle memory tracking, logs streaming and the different exit code of the container properly.
85+
It will handle memory tracking, logs streaming and the different exit code of the container properly.
8686

8787
The default code is as follows:
8888

docs/getting_started/0_scripts_quickstart/7_docker_quickstart/index.mdx

Lines changed: 19 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -54,104 +54,25 @@ Below is a simple example of a script built using Bash to run Docker containers
5454

5555
```bash
5656
# shellcheck shell=bash
57-
# Bash script that calls docker as a client to the host daemon
58-
# See documentation: https://www.windmill.dev/docs/advanced/docker
57+
# docker
58+
# The annotation "docker" above is important, it tells windmill that after
59+
# the end of the bash script, it should manage the container at id $WM_JOB_ID:
60+
# pipe logs, monitor memory usage, kill container if job is cancelled.
61+
5962
msg="${1:-world}"
6063

6164
IMAGE="alpine:latest"
6265
COMMAND="/bin/echo Hello $msg"
6366

6467
# ensure that the image is up-to-date
6568
docker pull $IMAGE
66-
docker run --rm $IMAGE $COMMAND
67-
```
68-
69-
### Kubernetes
70-
71-
If you use kubernetes and would like to run your docker file directly on the kubernetes host, use the following script:
72-
73-
```
74-
# shellcheck shell=bash
75-
# Bash script that calls docker as a client to the host daemon
76-
# See documentation: https://www.windmill.dev/docs/advanced/docker
77-
msg="${1:-world}"
78-
79-
IMAGE="docker/whalesay:latest"
80-
COMMAND=(sh -c "cowsay $msg")
81-
82-
APISERVER=https://kubernetes.default.svc
83-
SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount
84-
NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)
85-
TOKEN=$(cat ${SERVICEACCOUNT}/token)
86-
CACERT=${SERVICEACCOUNT}/ca.crt
87-
88-
KUBECONFIG_TMP_DIR="$(mktemp -d)"
89-
export KUBECONFIG="${KUBECONFIG_TMP_DIR}/kubeconfig"
90-
91-
trap "rm -rfv ${KUBECONFIG_TMP_DIR}" EXIT
92-
93-
kubectl config set-cluster local --server="${APISERVER}" --certificate-authority="${CACERT}"
94-
kubectl config set-credentials local --token="${TOKEN}"
95-
kubectl config set-context local --cluster=local --user=local --namespace="${NAMESPACE}"
96-
kubectl config use-context local
97-
98-
kubectl run task -it --rm --restart=Never --image="$IMAGE" -- "${COMMAND[@]}"
99-
```
100-
101-
and use the following additional privileges
10269

103-
```yaml
104-
---
105-
apiVersion: rbac.authorization.k8s.io/v1
106-
kind: Role
107-
metadata:
108-
namespace: windmill
109-
name: pod-management
110-
rules:
111-
- apiGroups: ['']
112-
resources: ['pods']
113-
verbs: ['get', 'list', 'watch', 'create', 'update', 'patch', 'delete']
114-
- apiGroups: ['']
115-
resources: ['pods/log']
116-
verbs: ['get', 'list', 'watch']
117-
- apiGroups: ['']
118-
resources: ['pods/attach']
119-
verbs: ['get', 'list', 'watch', 'create', 'update', 'patch', 'delete']
120-
- apiGroups: ['']
121-
resources: ['events']
122-
verbs: ['get', 'list', 'watch']
123-
---
124-
apiVersion: rbac.authorization.k8s.io/v1
125-
kind: RoleBinding
126-
metadata:
127-
name: pod-management
128-
namespace: windmill
129-
subjects:
130-
- kind: ServiceAccount
131-
name: windmill-chart
132-
namespace: windmill
133-
roleRef:
134-
kind: Role
135-
name: pod-management
136-
apiGroup: rbac.authorization.k8s.io
70+
# if using the 'docker' mode, name it with $WM_JOB_ID for windmill to monitor it
71+
docker run --name $WM_JOB_ID -it -d $IMAGE $COMMAND
13772
```
13873

139-
## Setup
140-
141-
To set-up Docker, see:
142-
143-
<div className="grid grid-cols-2 gap-6 mb-4">
144-
<DocCard
145-
title="Docker Set-Up"
146-
description="Windmill supports running any Docker container through its Bash support."
147-
href="/docs/advanced/docker"
148-
/>
149-
</div>
150-
151-
## Use
74+
To see more details about to setup your kubernetes or docker-compose setup to run docker containers, see [Run docker containers](../../../advanced/7_docker/index.mdx)
15275

153-
From the Home page of Windmill App, click `+Script`. This will take you to the
154-
first step of script creation: Metadata.
15576

15677
## Settings
15778

@@ -209,35 +130,31 @@ boilerplate. Let's take a look:
209130

210131
```bash
211132
# shellcheck shell=bash
212-
# Bash script that calls docker as a client to the host daemon
213-
# See documentation: https://www.windmill.dev/docs/advanced/docker
133+
# docker
134+
# The annotation "docker" above is important, it tells windmill that after
135+
# the end of the bash script, it should manage the container at id $WM_JOB_ID:
136+
# pipe logs, monitor memory usage, kill container if job is cancelled.
137+
214138
msg="${1:-world}"
215139

216140
IMAGE="alpine:latest"
217141
COMMAND="/bin/echo Hello $msg"
218142

219143
# ensure that the image is up-to-date
220144
docker pull $IMAGE
221-
docker run --rm $IMAGE $COMMAND
145+
146+
# if using the 'docker' mode, name it with $WM_JOB_ID for windmill to monitor it
147+
docker run --name $WM_JOB_ID -it -d $IMAGE $COMMAND
222148
```
223149

224150
`msg` is just a normal Bash variable. It can be used to pass arguments to the script. This syntax is the standard Bash one to assign default values to parameters.
225151

226152
```
227-
docker run --rm <image> <command>
153+
docker run --name $WM_JOB_ID -it -d $IMAGE $COMMAND
228154
```
229155

230-
--rm is so that the container dispose itself after being executed. It helps unpollute the host.
231-
232-
The image is the docker image to run. It can be any image available on docker hub or any private registry. It can also be a local image.
233-
234-
The command is the command to run inside the container. It can be any command available in the image.
235-
236-
It is just a Bash script so it will behave exactly the same as a local command or if running this as an ssh command on the host. As a consequence, you can use any strategy to cache docker images or handle authentication.
237-
238-
Do not use the daemon mode `-d` otherwise the script will immediately return while the container continue to run in the background. However, in some cases, that might be what you want.
239-
240-
Like any Bash script, it will return the last line of the stdout. So be sure to print the return value from your command if you'd like to use it as a result.
156+
Windmill has a native docker support if the `# docker` annotation is used. It will assume a a docker socket is mounted like in the example above and will take over management of the container as soon as the script ends, assuming that the container was ran with the `$WM_JOB_ID` as name.
157+
Which is why you should use docker `-d` deamon mode so that the bash script terminates early.
241158

242159
### Instant preview & testing
243160

0 commit comments

Comments
 (0)