Last updated: 10 Dec 23 21:09:57 (UTC)
Faul, schnell, rekursiv und remote: Lokale Runner als auch Docker Handling für Dummies mit taskfile.dev
Public: https://joplin.cloud.nerdraum.de/shares/g4it2GmYmuOIpmSvdtMTXw
Democonfig
Dateistruktur
# tree . ├── Arbeit │ ├── DockerHostEins │ │ ├── StackEins │ │ │ └── docker-compose.yml │ │ └── Taskfile.yml │ ├── DockerHostZwei │ │ ├── StackEins │ │ │ └── docker-compose.yml │ │ └── Taskfile.yml │ └── Taskfile.yml -> ../Taskfile.yml ├── Privat │ ├── DockerHostEins │ │ ├── StackEins │ │ │ └── docker-compose.yml │ │ └── Taskfile.yml │ ├── DockerHostZwei │ │ ├── StackEins │ │ │ └── docker-compose.yml │ │ └── Taskfile.yml │ └── Taskfile.yml -> ../Taskfile.yml └── Taskfile.yml 10 directories, 11 files
# tree
.
├── Arbeit
│ ├── DockerHostEins
│ │ ├── StackEins
│ │ │ └── docker-compose.yml
│ │ └── Taskfile.yml
│ ├── DockerHostZwei
│ │ ├── StackEins
│ │ │ └── docker-compose.yml
│ │ └── Taskfile.yml
│ └── Taskfile.yml -> ../Taskfile.yml
├── Privat
│ ├── DockerHostEins
│ │ ├── StackEins
│ │ │ └── docker-compose.yml
│ │ └── Taskfile.yml
│ ├── DockerHostZwei
│ │ ├── StackEins
│ │ │ └── docker-compose.yml
│ │ └── Taskfile.yml
│ └── Taskfile.yml -> ../Taskfile.yml
└── Taskfile.yml
10 directories, 11 files
Aliases
alias doc="task template:doc --" alias xdoc="task template:docker --" alias swarm="xdoc swarm "
alias doc="task template:doc --"
alias xdoc="task template:docker --"
alias swarm="xdoc swarm "
Main Taskfile
Taskfile.yml (Nicht ändern!)
version: '3' env: DOCKER_HOST: MAIN::No HOST Defined DOCKER_HOST_NAME: MAIN::No NAME Defined DIR: '{{.USER_WORKING_DIR}}' tasks: doc: preconditions: - test -f {{.DIR}}/docker-compose.yml cmds: - echo -e \\n \ DOCKER_HOST = {{.DOCKER_HOST_NAME}}$reset_color - {{.DOCKER_HOST}} \\n \ ============================================================== \\n \ - cd {{.DIR}}; DOCKER_HOST={{.DOCKER_HOST}} docker-compose {{.CLI_ARGS}} - pwd silent: true docker: cmds: - echo -e \\n \ DOCKER_HOST = {{.DOCKER_HOST_NAME}} - {{.DOCKER_HOST}} \\n \ ============================================================== \\n \ - cd {{.DIR}}; DOCKER_HOST={{.DOCKER_HOST}} docker {{.CLI_ARGS}} silent: true
version: '3'
env:
DOCKER_HOST: MAIN::No HOST Defined
DOCKER_HOST_NAME: MAIN::No NAME Defined
DIR: '{{.USER_WORKING_DIR}}'
tasks:
doc:
preconditions:
- test -f {{.DIR}}/docker-compose.yml
cmds:
- echo -e \\n \
DOCKER_HOST = {{.DOCKER_HOST_NAME}}$reset_color - {{.DOCKER_HOST}} \\n \
============================================================== \\n \
- cd {{.DIR}}; DOCKER_HOST={{.DOCKER_HOST}} docker-compose {{.CLI_ARGS}}
- pwd
silent: true
docker:
cmds:
- echo -e \\n \
DOCKER_HOST = {{.DOCKER_HOST_NAME}} - {{.DOCKER_HOST}} \\n \
============================================================== \\n \
- cd {{.DIR}}; DOCKER_HOST={{.DOCKER_HOST}} docker {{.CLI_ARGS}}
silent: true
Host-Taskfile
Privat/DockerHostEins/Taskfile.yml: (Für jeden Remote Dockerhost die beiden Variablen in env: anpassen.)
version: '3' env: DOCKER_HOST_LOCAL: ssh://root@127.0.0.1 DOCKER_HOST_LOCAL_NAME: PrivatDockerHostEins includes: template: taskfile: ../Taskfile.yml vars: DOCKER_HOST: $DOCKER_HOST_LOCAL DOCKER_HOST_NAME: $DOCKER_HOST_LOCAL_NAME
version: '3'
env:
DOCKER_HOST_LOCAL: ssh://root@127.0.0.1
DOCKER_HOST_LOCAL_NAME: PrivatDockerHostEins
includes:
template:
taskfile: ../Taskfile.yml
vars:
DOCKER_HOST: $DOCKER_HOST_LOCAL
DOCKER_HOST_NAME: $DOCKER_HOST_LOCAL_NAME
Anwendungsbeispiele
Was geht? Zeig mir mal was der Stack grad tut
Originalbefehl:
DOCKER_HOST = ssh://root@127.0.0.1 docker-compose ps
DOCKER_HOST = ssh://root@127.0.0.1 docker-compose ps
Abkürzung:
doc ps
doc ps
Ausgabe:
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1 ============================================================== NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS synapse-admin awesometechnologies/synapse-admin "/docker-entrypoint.…" synapse-admin 3 months ago Up 4 days 0.0.0.0:5001->80/tcp, :::5001->80/tcp /taskfileDemo/Privat/PrivatDockerHostEins
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1
==============================================================
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
synapse-admin awesometechnologies/synapse-admin "/docker-entrypoint.…" synapse-admin 3 months ago Up 4 days 0.0.0.0:5001->80/tcp, :::5001->80/tcp
/taskfileDemo/Privat/PrivatDockerHostEins
Was geht Teil2? Zeig mir mal was der gesamte Docker Host grad tut
Originalbefehl:
DOCKER_HOST = ssh://root@127.0.0.1 docker ps
DOCKER_HOST = ssh://root@127.0.0.1 docker ps
Abkürzung:
xdoc ps
xdoc ps
Ausgabe:
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1 ============================================================== CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3a0e74734c36 awesometechnologies/synapse-admin "/docker-entrypoint.…" 21 min ago Up 21 minutes :::5001->80/tcp synapse-admin 887e255f0007 postgres:13 "docker-entrypoint.s…" 6 days ago Up 4 days 5432/tcp koel-database-1 8fecd8ec7b1c nodered/node-red:3.1-debian "./entrypoint.sh" 8 weeks ago Up 4 days (healthy) :::1880->1880/tcp nodered …
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1
==============================================================
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a0e74734c36 awesometechnologies/synapse-admin "/docker-entrypoint.…" 21 min ago Up 21 minutes :::5001->80/tcp synapse-admin
887e255f0007 postgres:13 "docker-entrypoint.s…" 6 days ago Up 4 days 5432/tcp koel-database-1
8fecd8ec7b1c nodered/node-red:3.1-debian "./entrypoint.sh" 8 weeks ago Up 4 days (healthy) :::1880->1880/tcp nodered
…
Führe einen Befehl im Stack/Container aus
(hier ps aux, gerne auch /bin/bash oder sonstwas)
Originalbefehl:
DOCKER_HOST = ssh://root@127.0.0.1 docker-compose exec -it synapse-admin ps aux
DOCKER_HOST = ssh://root@127.0.0.1 docker-compose exec -it synapse-admin ps aux
Abkürzung:
doc exec -it synapse-admin ps aux
doc exec -it synapse-admin ps aux
Ausgabe:
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1 ============================================================== PID USER TIME COMMAND 1 root 0:00 nginx: master process nginx -g daemon off; 22 nginx 0:00 nginx: worker process 23 nginx 0:00 nginx: worker process 24 nginx 0:00 nginx: worker process 25 nginx 0:00 nginx: worker process 26 nginx 0:00 nginx: worker process 27 nginx 0:00 nginx: worker process 28 nginx 0:00 nginx: worker process 29 nginx 0:00 nginx: worker process 30 nginx 0:00 nginx: worker process 31 nginx 0:00 nginx: worker process 32 nginx 0:00 nginx: worker process 33 nginx 0:00 nginx: worker process 40 root 0:00 ps aux /taskfileDemo/Privat/PrivatDockerHostEins
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1
==============================================================
PID USER TIME COMMAND
1 root 0:00 nginx: master process nginx -g daemon off;
22 nginx 0:00 nginx: worker process
23 nginx 0:00 nginx: worker process
24 nginx 0:00 nginx: worker process
25 nginx 0:00 nginx: worker process
26 nginx 0:00 nginx: worker process
27 nginx 0:00 nginx: worker process
28 nginx 0:00 nginx: worker process
29 nginx 0:00 nginx: worker process
30 nginx 0:00 nginx: worker process
31 nginx 0:00 nginx: worker process
32 nginx 0:00 nginx: worker process
33 nginx 0:00 nginx: worker process
40 root 0:00 ps aux
/taskfileDemo/Privat/PrivatDockerHostEins
Gib mir Informationen über den Container
Originalbefehl:
DOCKER_HOST = ssh://root@127.0.0.1 docker inspect synapse-admin | head
DOCKER_HOST = ssh://root@127.0.0.1 docker inspect synapse-admin | head
Abkürzung:
xdoc inspect synapse-admin | head
xdoc inspect synapse-admin | head
Ausgabe:
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1 ============================================================== [ { "Id": "ölfksjdlfkjsdölfkjsdölfkj", "Created": "2023-08-23T18:59:49.187636146Z", "Path": "/docker-entrypoint.sh", "Args": [ task: Failed to run task "template:docker": exit status 141 task: Failed to run task "template:docker": exit status 141 … Hier kämen je nach Container noch trölfzig Zeilen Information
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1
==============================================================
[
{
"Id": "ölfksjdlfkjsdölfkjsdölfkj",
"Created": "2023-08-23T18:59:49.187636146Z",
"Path": "/docker-entrypoint.sh",
"Args": [
task: Failed to run task "template:docker": exit status 141
task: Failed to run task "template:docker": exit status 141
…
Hier kämen je nach Container noch trölfzig Zeilen Information
Zeig mir die letzten paar Zeilen Log des Stacks
Originalbefehl:
DOCKER_HOST = ssh://root@127.0.0.1 docker-compose logs | tail
DOCKER_HOST = ssh://root@127.0.0.1 docker-compose logs | tail
Abkürzung:
doc logs | tail
doc logs | tail
Ausgabe:
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 26 synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 27 synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 28 synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 29 synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 30 synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 31 synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 32 synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 33 synapse-admin | 10.250.42.1 - - [08/Dec/2023:02:21:34 +0000] "GET / HTTP/1.1" 200 941 "-" "Mozilla/5.0 (compatible; NetcraftSurveyAgent/1.0; +info@netcraft.com)" "3.249.5.61" /taskfileDemo/Privat/PrivatDockerHostEins
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 26
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 27
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 28
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 29
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 30
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 31
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 32
synapse-admin | 2023/12/06 11:44:36 [notice] 1#1: start worker process 33
synapse-admin | 10.250.42.1 - - [08/Dec/2023:02:21:34 +0000] "GET / HTTP/1.1" 200 941 "-" "Mozilla/5.0 (compatible; NetcraftSurveyAgent/1.0; +info@netcraft.com)" "3.249.5.61"
/taskfileDemo/Privat/PrivatDockerHostEins
Beherzter Neustart des gesamten Stacks mit Ausgabe der Logs
Originalbefehl:
DOCKER_HOST = ssh://root@127.0.0.1 docker-compose down; DOCKER_HOST = ssh://root@127.0.0.1 docker-compose up -d; DOCKER_HOST = ssh://root@127.0.0.1 docker-compose logs -f;
DOCKER_HOST = ssh://root@127.0.0.1 docker-compose down; DOCKER_HOST = ssh://root@127.0.0.1 docker-compose up -d; DOCKER_HOST = ssh://root@127.0.0.1 docker-compose logs -f;
Abkürzung:
doc down; doc up -d; doc logs -f
doc down; doc up -d; doc logs -f
Ausgabe:
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1 ============================================================== [+] Running 2/2 ✔ Container synapse-admin Removed 0.6s ✔ Network adminmatrixlocalhost_default Removed 0.6s /taskfileDemo/Privat/PrivatDockerHostEins DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1 ============================================================== [+] Building 0.0s (0/0) [+] Running 2/2 ✔ Network adminmatrixlocalhost_default Created 0.2s ✔ Container synapse-admin Started 0.7s /taskfileDemo/Privat/PrivatDockerHostEins DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1 ============================================================== synapse-admin | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration synapse-admin | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ synapse-admin | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh synapse-admin | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf synapse-admin | 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf synapse-admin | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh synapse-admin | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh synapse-admin | /docker-entrypoint.sh: Configuration complete; ready for start up synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: using the "epoll" event method synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: nginx/1.23.3 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4) synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: OS: Linux 6.1.0-1008-oem synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker processes synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 30 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 31 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 32 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 33 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 34 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 35 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 36 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 37 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 38 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 39 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 40 synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 41 … Hier scrollt das Log weiter bis CTRL-C oder der Stack stirbt.
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1
==============================================================
[+] Running 2/2
✔ Container synapse-admin Removed 0.6s
✔ Network adminmatrixlocalhost_default Removed 0.6s
/taskfileDemo/Privat/PrivatDockerHostEins
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1
==============================================================
[+] Building 0.0s (0/0)
[+] Running 2/2
✔ Network adminmatrixlocalhost_default Created 0.2s
✔ Container synapse-admin Started 0.7s
/taskfileDemo/Privat/PrivatDockerHostEins
DOCKER_HOST = PrivatDockerHostEins - ssh://root@127.0.0.1
==============================================================
synapse-admin | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
synapse-admin | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
synapse-admin | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
synapse-admin | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
synapse-admin | 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
synapse-admin | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
synapse-admin | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
synapse-admin | /docker-entrypoint.sh: Configuration complete; ready for start up
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: using the "epoll" event method
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: nginx/1.23.3
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4)
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: OS: Linux 6.1.0-1008-oem
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker processes
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 30
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 31
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 32
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 33
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 34
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 35
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 36
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 37
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 38
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 39
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 40
synapse-admin | 2023/12/10 20:23:12 [notice] 1#1: start worker process 41
…
Hier scrollt das Log weiter bis CTRL-C oder der Stack stirbt.