| 1 | package App::dozo; | ||
| 2 | |||
| 3 | 1 | our $VERSION = "1.03"; | |
| 4 | |||
| 5 | 1 | 1; | |
| 6 | =encoding utf-8 | ||
| 7 | |||
| 8 | =for html <p align="center"><img src="https://raw.githubusercontent.com/tecolicom/App-dozo/main/images/dozo-logo.png" width="400"></p> | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | dozo - Dôzo, Docker with Zero Overhead | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | dozo -I IMAGE [ options ] [ command ... ] | ||
| 17 | |||
| 18 | -h, --help show help | ||
| 19 | --version show version | ||
| 20 | --bundle print a self-contained dozo | ||
| 21 | -d, --debug debug mode (show full command) | ||
| 22 | -x, --trace trace mode (set -x) | ||
| 23 | -q, --quiet quiet mode | ||
| 24 | -n, --dryrun dry-run mode | ||
| 25 | |||
| 26 | -I, --image=# Docker image (required unless -D) | ||
| 27 | -D, --default use default image | ||
| 28 | -A, --auto-pull pull newer image before running | ||
| 29 | -F, --with=# add features to the image (repeatable) | ||
| 30 | -E, --env=# environment variable to inherit (repeatable) | ||
| 31 | -W, --mount-cwd mount current working directory | ||
| 32 | -H, --mount-home mount home directory | ||
| 33 | -U, --unmount do not mount any directory | ||
| 34 | --mount-mode=# mount mode (rw or ro, default: rw) | ||
| 35 | -R, --mount-ro mount read-only (shortcut for --mount-mode=ro) | ||
| 36 | -V, --volume=# additional volume to mount (repeatable) | ||
| 37 | -B, --batch batch mode (non-interactive) | ||
| 38 | -L, --live use live (persistent) container | ||
| 39 | -N, --name=# live container name | ||
| 40 | -K, --kill kill and remove existing container | ||
| 41 | -P, --port=# port mapping (repeatable) | ||
| 42 | -O, --other=# additional docker options (repeatable) | ||
| 43 | -S, --status show live containers and derived images | ||
| 44 | |||
| 45 | =head1 VERSION | ||
| 46 | |||
| 47 | Version 1.03 | ||
| 48 | |||
| 49 | =head1 USAGE | ||
| 50 | |||
| 51 | When executed without arguments, Dôzo starts an interactive shell | ||
| 52 | inside the container. When arguments are given, they are executed as | ||
| 53 | a command. | ||
| 54 | |||
| 55 | dozo -I alpine # start shell | ||
| 56 | dozo -I alpine ls -la # run command | ||
| 57 | |||
| 58 | By setting C<-D> or your favorite image with C<-I> in F<~/.dozorc>, | ||
| 59 | you can simply run Dôzo without specifying an image. Since the git | ||
| 60 | top directory is automatically mounted, git commands work as expected | ||
| 61 | from anywhere in the tree. | ||
| 62 | |||
| 63 | $ dozo # start shell | ||
| 64 | $ dozo git log -p # run git log -p | ||
| 65 | |||
| 66 | With C<-L> option, you can use a persistent container. Tools | ||
| 67 | installed in the container will remain available for subsequent use. | ||
| 68 | |||
| 69 | $ dozo -L # start shell and create container | ||
| 70 | # apt update && apt install -y cowsay | ||
| 71 | # exit | ||
| 72 | $ dozo -L /usr/games/cowsay Dôzo | ||
| 73 | ______ | ||
| 74 | < Dôzo > | ||
| 75 | ------ | ||
| 76 | \ ^__^ | ||
| 77 | \ (oo)\_______ | ||
| 78 | (__)\ )\/\ | ||
| 79 | ||----w | | ||
| 80 | || || | ||
| 81 | |||
| 82 | =cut | ||
| 83 | =head1 INSTALLATION | ||
| 84 | |||
| 85 | Using L<cpanminus|https://metacpan.org/pod/App::cpanminus>: | ||
| 86 | |||
| 87 | cpanm -n App::dozo | ||
| 88 | |||
| 89 | To install the latest version from GitHub: | ||
| 90 | |||
| 91 | cpanm -n https://github.com/tecolicom/App-dozo.git | ||
| 92 | |||
| 93 | Alternatively, you can simply place C<dozo> and C<getoptlong.sh> in | ||
| 94 | your PATH. | ||
| 95 | |||
| 96 | A self-contained single file, which needs no other part of the | ||
| 97 | distribution, is attached to each release on GitHub; download it and | ||
| 98 | place it in your PATH: | ||
| 99 | |||
| 100 | curl -fsSLo ~/.local/bin/dozo \ | ||
| 101 | https://github.com/tecolicom/App-dozo/releases/download/VERSION/dozo | ||
| 102 | chmod +x ~/.local/bin/dozo | ||
| 103 | |||
| 104 | The same file is made by C<dozo --bundle> from an installed B<Dôzo>, | ||
| 105 | also inside the default image once it carries a B<Dôzo> with this | ||
| 106 | option: | ||
| 107 | |||
| 108 | docker run --rm tecolicom/xlate dozo --bundle > dozo | ||
| 109 | |||
| 110 | B<Dôzo> requires Bash 4.4 or later, as does the C<getoptlong.sh> | ||
| 111 | script it uses. | ||
| 112 | |||
| 113 | =head1 DESCRIPTION | ||
| 114 | |||
| 115 | B<Dôzo> is a generic Docker runner that simplifies running commands in | ||
| 116 | Docker containers. The name comes from the Japanese word "dôzo" | ||
| 117 | (どうぞ) meaning "please" or "go ahead", and also stands for "B<D>ocker | ||
| 118 | with B<Z>ero B<O>verhead". The command name is C<dozo> for ease of | ||
| 119 | typing. | ||
| 120 | |||
| 121 | It automatically configures the tedious Docker options such as volume | ||
| 122 | mounts, environment variables, working directories, and interactive | ||
| 123 | terminal settings, so you can focus on the command you want to run. | ||
| 124 | |||
| 125 | B<Dôzo> is distributed as a standalone module and can be used as a | ||
| 126 | general-purpose Docker runner. It was originally developed as part of | ||
| 127 | L<App::Greple::xlate> and is used by L<xlate> for Docker operations. | ||
| 128 | |||
| 129 | B<Dôzo> uses L<getoptlong.sh|https://github.com/tecolicom/getoptlong> | ||
| 130 | for option parsing. | ||
| 131 | |||
| 132 | =head2 Key Features | ||
| 133 | |||
| 134 | =over 4 | ||
| 135 | |||
| 136 | =item B<Git Friendly> | ||
| 137 | |||
| 138 | If you are working in a git environment, the git top directory is | ||
| 139 | automatically mounted. Otherwise the current directory is mounted. | ||
| 140 | When the current directory is under the git top directory, the | ||
| 141 | corresponding subdirectory in the container is used as the working | ||
| 142 | directory. | ||
| 143 | |||
| 144 | =item B<Live Container> | ||
| 145 | |||
| 146 | Use C<-L> to create or attach to a persistent container that survives | ||
| 147 | between invocations. Container names are automatically generated from | ||
| 148 | the image name and mount directory. | ||
| 149 | |||
| 150 | =item B<Environment Inheritance> | ||
| 151 | |||
| 152 | Common environment variables are automatically inherited: C<LANG>, | ||
| 153 | C<TZ>, proxy settings, terminal settings, and API keys for AI/LLM | ||
| 154 | services (DeepL, OpenAI, Anthropic, Perplexity). | ||
| 155 | |||
| 156 | =item B<Flexible Mounting> | ||
| 157 | |||
| 158 | The directory is mounted on F</work> in the container, and it is used | ||
| 159 | as the working directory. Various mount options are available: current | ||
| 160 | directory (C<-W>), home directory (C<-H>), additional volumes (C<-V>), | ||
| 161 | read-only mode (C<-R>), or no mount (C<-U>). | ||
| 162 | |||
| 163 | =item B<X11 Support> | ||
| 164 | |||
| 165 | When C<DISPLAY> is set, the address of the interface used for the | ||
| 166 | default route is detected and passed to the container as C<DISPLAY>, | ||
| 167 | enabling GUI applications. | ||
| 168 | |||
| 169 | =item B<Configuration File> | ||
| 170 | |||
| 171 | Use C<.dozorc> to set default options. Loaded from the home directory, | ||
| 172 | the git top directory, and the current directory, in that order, so | ||
| 173 | that a closer file takes precedence. | ||
| 174 | |||
| 175 | =item B<Standalone Operation> | ||
| 176 | |||
| 177 | B<Dôzo> can operate independently of L<xlate>. The C<getoptlong.sh> | ||
| 178 | script is provided by the L<Getopt::Long::Bash> CPAN distribution, | ||
| 179 | which is installed as a dependency. Alternatively, you can place | ||
| 180 | C<getoptlong.sh> in your C<PATH> manually. | ||
| 181 | |||
| 182 | =back | ||
| 183 | |||
| 184 | =head1 OPTIONS | ||
| 185 | |||
| 186 | Repeatable options (B<-E>, B<-V>, B<-P>, B<-O> and B<--with>) can be | ||
| 187 | given more than once, and a single value is also split into multiple | ||
| 188 | elements at commas; spaces around a comma are ignored. Thus | ||
| 189 | C<-P 8000,9000> gives two port mappings. B<-P> and B<-O> are split | ||
| 190 | at spaces and tabs as well, so B<-O> with the value C<--memory 2g> | ||
| 191 | gives two docker options. The others keep spaces in a value: B<-E> | ||
| 192 | with the value C<MSG=hello world> defines one variable. Use | ||
| 193 | B<--no->I<option> (e.g. B<--no-with>) to discard the values given so | ||
| 194 | far, including those in F<.dozorc>. | ||
| 195 | |||
| 196 | =over 7 | ||
| 197 | |||
| 198 | =item B<-h>, B<--help> | ||
| 199 | |||
| 200 | Show help message. | ||
| 201 | |||
| 202 | =item B<--version> | ||
| 203 | |||
| 204 | Show version number. | ||
| 205 | |||
| 206 | =item B<--bundle> | ||
| 207 | |||
| 208 | Print a self-contained B<Dôzo>, which includes what it needs from | ||
| 209 | the distribution, and exit without running Docker. The result is a | ||
| 210 | single file that runs where only Bash 4.4 or later and Docker are | ||
| 211 | available: | ||
| 212 | |||
| 213 | dozo --bundle > ~/.local/bin/dozo-single | ||
| 214 | |||
| 215 | A file made this way prints itself again. | ||
| 216 | |||
| 217 | =item B<-d>, B<--debug> | ||
| 218 | |||
| 219 | Enable debug mode. Shows the full docker command line that will be executed. | ||
| 220 | |||
| 221 | =item B<-x>, B<--trace> | ||
| 222 | |||
| 223 | Enable trace mode (set -x). | ||
| 224 | |||
| 225 | =item B<-q>, B<--quiet> | ||
| 226 | |||
| 227 | Quiet mode. Suppress the informational line printed to standard error | ||
| 228 | before the container is started: | ||
| 229 | |||
| 230 | docker run image=alpine env=13 command=echo hi | ||
| 231 | |||
| 232 | It summarizes the image name, the number of environment variables to be | ||
| 233 | inherited, the container name (with B<-L>) and the command to be | ||
| 234 | executed. This line is shown regardless of B<-n>; use B<-d> to see the | ||
| 235 | whole docker command line instead. | ||
| 236 | |||
| 237 | =item B<-n>, B<--dryrun> | ||
| 238 | |||
| 239 | Dry-run mode. Show docker commands without executing them. | ||
| 240 | Useful for testing and debugging. | ||
| 241 | |||
| 242 | =item B<-I> I<image>, B<--image>=I<image> | ||
| 243 | |||
| 244 | Specify Docker image. Required unless C<-D> is given, but you can put | ||
| 245 | it in F<.dozorc> so you don't have to type it every time. | ||
| 246 | |||
| 247 | =item B<-D>, B<--default> | ||
| 248 | |||
| 249 | Use the default Docker image. If C<DOZO_DEFAULT_IMAGE> environment | ||
| 250 | variable is set, use that image. Otherwise, use C<tecolicom/xlate>, | ||
| 251 | that is, its C<latest> tag. See L</DEFAULT IMAGE> section for details | ||
| 252 | about the default image. | ||
| 253 | |||
| 254 | =item B<-A>, B<--auto-pull> | ||
| 255 | |||
| 256 | Run C<docker pull> before running the command, so that a newer image | ||
| 257 | is downloaded when the registry has one. Nothing is downloaded | ||
| 258 | without this option once the image is on the machine. When the pull | ||
| 259 | fails, as it does when offline, a warning is shown and the command | ||
| 260 | runs on the local image. | ||
| 261 | |||
| 262 | An existing live container stays as it is, on the image it was created | ||
| 263 | from; use C<-KL> to recreate it. | ||
| 264 | |||
| 265 | =item B<-E> I<name>[=I<value>], B<--env>=I<name>[=I<value>] | ||
| 266 | |||
| 267 | Specify environment variable to pass to the container. If I<value> is | ||
| 268 | omitted, the value is inherited from the host environment. Repeatable. | ||
| 269 | |||
| 270 | =item B<-W>, B<--mount-cwd> | ||
| 271 | |||
| 272 | Mount current working directory. | ||
| 273 | |||
| 274 | =item B<-H>, B<--mount-home> | ||
| 275 | |||
| 276 | Mount home directory. The C<HOME> environment variable in the | ||
| 277 | container is set to the mount point (F</work>). | ||
| 278 | |||
| 279 | =item B<-U>, B<--unmount> | ||
| 280 | |||
| 281 | Do not mount any directory. | ||
| 282 | |||
| 283 | =item B<--mount-mode>=I<mode> | ||
| 284 | |||
| 285 | Set mount mode of the automatically mounted directory. I<mode> is | ||
| 286 | either C<rw> (read-write, default) or C<ro> (read-only). This does not | ||
| 287 | affect volumes given by B<-V>; append C<:ro> to them instead. | ||
| 288 | |||
| 289 | =item B<-R>, B<--mount-ro> | ||
| 290 | |||
| 291 | Mount directory as read-only. Shortcut for C<--mount-mode=ro>. | ||
| 292 | |||
| 293 | =item B<-V> I<path>, B<-V> I<from>:I<to>, B<--volume>=I<from>:I<to> | ||
| 294 | |||
| 295 | Specify additional directory to mount. If only I<path> is given | ||
| 296 | (without C<:>), it is mounted to the same path in the container; a | ||
| 297 | relative path is resolved against the current directory. Repeatable. | ||
| 298 | |||
| 299 | =item B<-B>, B<--batch> | ||
| 300 | |||
| 301 | Run in batch mode (non-interactive): the container gets no terminal | ||
| 302 | and does not wait for input from one. Input from a pipe or a file is | ||
| 303 | still passed to the command, as in C<git diff | dozo -B cdif>. | ||
| 304 | |||
| 305 | =item B<-L>, B<--live> | ||
| 306 | |||
| 307 | Use live (persistent) container. | ||
| 308 | |||
| 309 | =item B<-N> I<name>, B<--name>=I<name> | ||
| 310 | |||
| 311 | Specify container name explicitly. | ||
| 312 | |||
| 313 | =item B<-K>, B<--kill> | ||
| 314 | |||
| 315 | Kill and remove existing container. | ||
| 316 | |||
| 317 | =item B<-P> I<port>, B<-P> I<host>:I<container>, B<--port>=I<host>:I<container> | ||
| 318 | |||
| 319 | Specify port mapping. If only I<port> is given (without C<:>), it is | ||
| 320 | mapped to the same port in the container (e.g., C<-P 8000> becomes | ||
| 321 | C<8000:8000>, and C<-P 8000/udp> becomes C<8000:8000/udp>). | ||
| 322 | Repeatable. | ||
| 323 | |||
| 324 | =item B<-O> I<option>, B<--other>=I<option> | ||
| 325 | |||
| 326 | Specify additional docker options. Repeatable. | ||
| 327 | |||
| 328 | =item B<-F> I<name>[/I<arg>][,...], B<--with>=I<name>[/I<arg>][,...] | ||
| 329 | |||
| 330 | Run the image with the named features added. A feature is a piece of | ||
| 331 | Dockerfile kept in F<~/.config/dozo/features/> (or under | ||
| 332 | C<XDG_CONFIG_HOME>), and the image made from the base image with the | ||
| 333 | features applied in order is used instead of the base image. A name | ||
| 334 | may be followed by C</> and an argument for the feature. Names are | ||
| 335 | separated by comma, and the option is repeatable: values given in | ||
| 336 | F<.dozorc> and on the command line accumulate (F<.dozorc> first). | ||
| 337 | See L</FEATURES> section for details. | ||
| 338 | |||
| 339 | =item B<-S>, B<--status> | ||
| 340 | |||
| 341 | Show the status, and change nothing: what B<-L> would do here and | ||
| 342 | why (the mounted directory, the image and where it is given, the | ||
| 343 | container it would use or make, the image of B<--with>), the live | ||
| 344 | containers and the derived images made by B<dozo>, and the commands | ||
| 345 | to remove those which are no longer used. Nothing is pulled, built, | ||
| 346 | started or removed. It takes no command. Give it with other options | ||
| 347 | to see what they would do: C<dozo -I alpine -S>, C<dozo --with locale | ||
| 348 | -S>, C<dozo -KL -S>. See L</Show the status>. | ||
| 349 | |||
| 350 | =back | ||
| 351 | |||
| 352 | =head1 INTERACTIVE MODE | ||
| 353 | |||
| 354 | The container is started with Docker's C<--interactive> option, and | ||
| 355 | C<--tty> is added as well when the standard input is a terminal (TTY). | ||
| 356 | With the B<-B> (batch) option, neither is given when the standard | ||
| 357 | input is a terminal, so that nothing waits for keyboard input; when | ||
| 358 | the standard input is a pipe or a file, C<--interactive> is still | ||
| 359 | given so that the input reaches the command. The same rule is | ||
| 360 | applied to C<docker exec> in live container mode. | ||
| 361 | |||
| 362 | This allows seamless interactive use when attaching to containers or | ||
| 363 | running interactive commands. | ||
| 364 | |||
| 365 | =head1 LIVE CONTAINER | ||
| 366 | |||
| 367 | The C<-L> option enables live (persistent) container mode. Unlike | ||
| 368 | normal mode where containers are removed after execution (C<--rm>), | ||
| 369 | live containers persist between invocations, allowing you to maintain | ||
| 370 | state and reduce startup overhead. | ||
| 371 | |||
| 372 | =head2 Container Lifecycle | ||
| 373 | |||
| 374 | When C<-L> is specified, B<Dôzo> behaves as follows: | ||
| 375 | |||
| 376 | =over 4 | ||
| 377 | |||
| 378 | =item 1. B<Container does not exist> | ||
| 379 | |||
| 380 | Create a new persistent container (without C<--rm> flag). Without a | ||
| 381 | command, the container is started with the image's default command | ||
| 382 | (usually a shell) and you are connected to it. With a command, the | ||
| 383 | container is started in the background with the default command, | ||
| 384 | and then the command is executed in it as in case 2. So you can | ||
| 385 | build up an environment from the first invocation, even in batch | ||
| 386 | mode: | ||
| 387 | |||
| 388 | dozo -L -B apt-get install -y foo | ||
| 389 | dozo -L -B pip install bar | ||
| 390 | |||
| 391 | If the image has an entrypoint, the command is given to it as | ||
| 392 | arguments, and the container stops when it finishes. | ||
| 393 | |||
| 394 | =item 2. B<Container exists and is running> | ||
| 395 | |||
| 396 | If a command is given, execute it using C<docker exec>. Otherwise, | ||
| 397 | attach to the container using C<docker attach>. | ||
| 398 | |||
| 399 | =item 3. B<Container exists but is paused> | ||
| 400 | |||
| 401 | Unpause the container with C<docker unpause>, then proceed as above. | ||
| 402 | |||
| 403 | =item 4. B<Container exists but is not started> | ||
| 404 | |||
| 405 | If the container is in the C<created> or C<exited> state, start it | ||
| 406 | with C<docker start>, then proceed as above. | ||
| 407 | |||
| 408 | =back | ||
| 409 | |||
| 410 | =head2 Container Naming | ||
| 411 | |||
| 412 | Container names are automatically generated in the format: | ||
| 413 | |||
| 414 | <image_name>.<mount_directory> | ||
| 415 | |||
| 416 | For example, if you run: | ||
| 417 | |||
| 418 | dozo -I tecolicom/xlate -L | ||
| 419 | |||
| 420 | from C</home/user/project>, the container name would be | ||
| 421 | C<xlate.project>. | ||
| 422 | |||
| 423 | The name is made from the last part of the image name only, without | ||
| 424 | the tag, the owner or the registry: C<alpine> and C<alpine:3.18>, or | ||
| 425 | C<tecolicom/xlate> and C<other/xlate>, give the same name, and an | ||
| 426 | existing container is used for both. When the image of the existing | ||
| 427 | container differs from the one given by B<-I>, B<dozo> tells so; use | ||
| 428 | B<-K> to recreate the container, or B<-N> to give another name. | ||
| 429 | |||
| 430 | You can override the auto-generated name using the C<-N> option: | ||
| 431 | |||
| 432 | dozo -I tecolicom/xlate -L -N mycontainer | ||
| 433 | |||
| 434 | The name also has only the last part of the mounted directory, so | ||
| 435 | F</a/project> and F</b/project> give the same name. A live container | ||
| 436 | has the label C<dozo.mount> with the full physical path of the | ||
| 437 | mounted directory (a directory reached through a symlink is the same | ||
| 438 | directory), C<dozo.image> with the image given by B<-I>, and | ||
| 439 | C<dozo.version> with the version of B<dozo> that made it. If the | ||
| 440 | container found by a name made from B<-I> is of another | ||
| 441 | directory, B<dozo> stops instead of running the command on the files | ||
| 442 | of that directory; give another name with B<-N>. A name given by | ||
| 443 | B<-N> is not checked, and nor is a container made by an older | ||
| 444 | B<dozo>, which has no label. | ||
| 445 | |||
| 446 | =head2 Managing Live Containers | ||
| 447 | |||
| 448 | =over 4 | ||
| 449 | |||
| 450 | =item B<Use the container of this directory> | ||
| 451 | |||
| 452 | dozo -I myimage -L # start working | ||
| 453 | dozo -L # later: connect to the same container | ||
| 454 | dozo -L make test # run a command in it | ||
| 455 | dozo -KL # make it again from the same image | ||
| 456 | dozo -K # remove it | ||
| 457 | |||
| 458 | When neither B<-I>, B<-D> nor B<-N> is on the command line, B<-L> | ||
| 459 | and B<-K> use the container made for the mounted directory, found by | ||
| 460 | its C<dozo.mount> label. In a git repository this is the top | ||
| 461 | directory, so the same container is used from any subdirectory. If | ||
| 462 | there are several of them (made from different images), B<dozo> lists | ||
| 463 | them; choose one with B<-I> or B<-N>. B<-KL> makes the container | ||
| 464 | again from the image in its C<dozo.image> label. | ||
| 465 | |||
| 466 | An image set in F<.dozorc> (by B<-I> or B<-D>) is a default: it is | ||
| 467 | used only when there is no container for the directory. So with | ||
| 468 | B<-D> in F<~/.dozorc>, B<dozo -L> connects to the container started | ||
| 469 | by B<dozo -I myimage -L> in this directory, and to the one of the | ||
| 470 | default image elsewhere. B<-I> or B<-D> on the command line always | ||
| 471 | chooses the container of that image. | ||
| 472 | |||
| 473 | =item B<Attach to existing container> | ||
| 474 | |||
| 475 | dozo -I myimage -L | ||
| 476 | |||
| 477 | If no command is given, attaches to the container's main process. | ||
| 478 | |||
| 479 | =item B<Execute command in existing container> | ||
| 480 | |||
| 481 | dozo -I myimage -L ls -la | ||
| 482 | |||
| 483 | Runs the command in the existing container using C<docker exec>. | ||
| 484 | Environment variables are passed just as for a new container, and when | ||
| 485 | the current directory is under the mounted directory, the | ||
| 486 | corresponding subdirectory is used as the working directory. | ||
| 487 | |||
| 488 | =item B<Kill and recreate container> | ||
| 489 | |||
| 490 | dozo -I myimage -KL | ||
| 491 | |||
| 492 | The C<-K> option removes the existing container before C<-L> creates | ||
| 493 | a new one. Useful when you need a fresh container state. | ||
| 494 | |||
| 495 | =item B<Kill container only> | ||
| 496 | |||
| 497 | dozo -I myimage -K | ||
| 498 | |||
| 499 | Without C<-L>, the container is removed and the command exits. | ||
| 500 | |||
| 501 | =item B<Show the status> | ||
| 502 | |||
| 503 | dozo -S | ||
| 504 | |||
| 505 | Shows what B<dozo -L> would do in this directory, and lists the live | ||
| 506 | containers and the derived images (see L</Derived Images>): | ||
| 507 | |||
| 508 | /home/me/project: | ||
| 509 | image tecolicom/xlate (/home/me/.dozorc) | ||
| 510 | container xlate.project, exited (found by label) | ||
| 511 | --with locale: dozo/xlate:locale-3580643729 (exists) | ||
| 512 | |||
| 513 | live containers: | ||
| 514 | NAME STATUS IMAGE DIRECTORY NOTE | ||
| 515 | * xlate.project exited tecolicom/xlate ~/project with dozo/xlate:locale-3580643729 | ||
| 516 | xlate.old exited tecolicom/xlate ~/old no label, gone | ||
| 517 | |||
| 518 | derived images: | ||
| 519 | IMAGE BASE WITH STATE CREATED | ||
| 520 | * dozo/xlate:locale-3580643729 tecolicom/xlate locale current 2 hours ago | ||
| 521 | dozo/brew:locale-2017098170 homebrew/brew locale outdated 3 days ago | ||
| 522 | |||
| 523 | to clean up: | ||
| 524 | docker rm xlate.old | ||
| 525 | docker image rm dozo/brew:locale-2017098170 | ||
| 526 | |||
| 527 | C<*> marks what this directory uses. The containers are those made | ||
| 528 | by B<dozo> (also those made before the C<dozo.mount> label, shown with | ||
| 529 | C<no label>), and not those run without B<-L>. A container whose | ||
| 530 | directory does not exist any more (C<gone>) is to clean up; one whose | ||
| 531 | image has been updated since it was made can be made again with | ||
| 532 | B<-KL>. Where B<-L> would stop with an error (several containers for | ||
| 533 | the directory, a container of another directory), the status tells it | ||
| 534 | as a C<note> instead. B<dozo> removes nothing: copy the commands | ||
| 535 | under C<to clean up> to remove them. | ||
| 536 | |||
| 537 | =back | ||
| 538 | |||
| 539 | =head1 FEATURES | ||
| 540 | |||
| 541 | A I<feature> is a named piece of Dockerfile that is added to any | ||
| 542 | image. It is a way to bring your usual setup (locale, dot files, | ||
| 543 | environment variables, ...) to an image made by someone else: | ||
| 544 | |||
| 545 | dozo -I homebrew/brew --with locale,home make test | ||
| 546 | |||
| 547 | Features are not bundled with B<dozo>; you write your own. | ||
| 548 | |||
| 549 | =head2 Feature Directory | ||
| 550 | |||
| 551 | Features are looked up in | ||
| 552 | F<${XDG_CONFIG_HOME:-$HOME/.config}/dozo/features/>. A name which | ||
| 553 | contains C</> or starts with C<.> is rejected, and a missing feature | ||
| 554 | is an error. A feature takes one of two forms. | ||
| 555 | |||
| 556 | =over 4 | ||
| 557 | |||
| 558 | =item B<File> | ||
| 559 | |||
| 560 | F<features/NAME> is a fragment of Dockerfile (C<RUN>, C<ENV>, C<USER>, | ||
| 561 | and so on). | ||
| 562 | |||
| 563 | =item B<Directory> | ||
| 564 | |||
| 565 | F<features/NAME/Dockerfile> is the fragment, and the directory itself | ||
| 566 | is the build context, so C<COPY> can copy files in it. Files made by | ||
| 567 | Finder and editors (F<.DS_Store>, F<*~>, F<.*.sw?>, F<#*#>, F<.#*>) | ||
| 568 | do not cause a rebuild, but they are still in the context, and so is | ||
| 569 | F<Dockerfile> itself; C<COPY . ...> copies them too. To keep them | ||
| 570 | out of the image, list them in F<.dockerignore>: | ||
| 571 | |||
| 572 | Dockerfile | ||
| 573 | .dockerignore | ||
| 574 | .DS_Store | ||
| 575 | *~ | ||
| 576 | .*.sw? | ||
| 577 | |||
| 578 | =back | ||
| 579 | |||
| 580 | B<dozo> gives these values as Dockerfile C<ARG>: | ||
| 581 | |||
| 582 | =over 4 | ||
| 583 | |||
| 584 | =item C<DOZO_USER> | ||
| 585 | |||
| 586 | The user of the base image (C<root> if the image sets none). | ||
| 587 | |||
| 588 | =item C<DOZO_HOME> | ||
| 589 | |||
| 590 | The home directory of that user. | ||
| 591 | |||
| 592 | =item C<DOZO_ARG> | ||
| 593 | |||
| 594 | The argument given as I<name>C</>I<arg> (empty without it). | ||
| 595 | |||
| 596 | =back | ||
| 597 | |||
| 598 | A feature may switch to C<USER root>. At the end of each feature, | ||
| 599 | B<dozo> restores the original user of the base image (nothing is done | ||
| 600 | if the image sets none). | ||
| 601 | |||
| 602 | =head2 Arguments | ||
| 603 | |||
| 604 | A feature can take an argument, given after the first C</> of the | ||
| 605 | name: C<--with locale/ja_JP> passes C<ja_JP> to the feature | ||
| 606 | F<locale> as C<DOZO_ARG>. Everything after the first C</> is the | ||
| 607 | argument, so it may contain C</> itself (C<zone/Asia/Tokyo>), and | ||
| 608 | spaces when quoted, but not a comma, which separates features. | ||
| 609 | C<locale/> is the same as C<locale>. The argument is given by | ||
| 610 | C<docker build --build-arg>, and is available as C<$DOZO_ARG> in the | ||
| 611 | feature. | ||
| 612 | |||
| 613 | Different arguments make different images, and each of them is | ||
| 614 | reused. B<dozo> does not split the argument; to take several values, | ||
| 615 | pick a separator and split it with C<IFS> in the feature (see | ||
| 616 | F<features/locale> below): | ||
| 617 | |||
| 618 | dozo -I homebrew/brew --with locale/ja_JP+en_US make test | ||
| 619 | |||
| 620 | =head2 Examples | ||
| 621 | |||
| 622 | F<features/locale>, which makes UTF-8 locales on Debian and Ubuntu | ||
| 623 | based images: C<--with locale> makes C<ja_JP.UTF-8>, and | ||
| 624 | C<--with locale/ja_JP+en_US> makes C<ja_JP.UTF-8> and | ||
| 625 | C<en_US.UTF-8>. B<dozo> gives C<LANG> of the host to the container, | ||
| 626 | so making the locale is enough. It does nothing when the image has | ||
| 627 | the locales already, or has neither C<locale-gen> nor C<apt-get> | ||
| 628 | (such as alpine), so it can be given always in F<~/.dozorc>: | ||
| 629 | |||
| 630 | --with locale | ||
| 631 | |||
| 632 | It is included in the distribution, in F<share/features/locale>. | ||
| 633 | B<dozo> does not look there: copy it to the feature directory. For | ||
| 634 | an installed distribution (with L<File::ShareDir>): | ||
| 635 | |||
| 636 | mkdir -p ~/.config/dozo/features | ||
| 637 | cp "$(perl -MFile::ShareDir=dist_dir -E 'say dist_dir "App-dozo"')"/features/locale \ | ||
| 638 | ~/.config/dozo/features/ | ||
| 639 | |||
| 640 | The comments in the file tell how it works. | ||
| 641 | |||
| 642 | F<features/home/Dockerfile>, with other files in F<features/home/>: | ||
| 643 | |||
| 644 | COPY --chown=$DOZO_USER . $DOZO_HOME/ | ||
| 645 | RUN exec >> $DOZO_HOME/.inputrc \ | ||
| 646 | && echo Control-n: history-search-forward \ | ||
| 647 | && echo Control-p: history-search-backward | ||
| 648 | |||
| 649 | =head2 Derived Images | ||
| 650 | |||
| 651 | Each feature makes one image on top of the previous one, tagged | ||
| 652 | C<dozo/>I<base>C<:>I<name>C<->I<cksum>. The checksum is made from | ||
| 653 | the parent image, the content of the feature (for a directory, the | ||
| 654 | names and contents of all files in it) and its argument. An image | ||
| 655 | which already exists is reused and nothing is built, so the second and | ||
| 656 | later runs only add one image check per stage (a few tens of | ||
| 657 | milliseconds). When a feature or the base image (for example updated | ||
| 658 | by B<-A>) changes, the image is made again from that feature on, and | ||
| 659 | earlier images are reused. Put heavy features first. | ||
| 660 | |||
| 661 | A base image which is not found locally is pulled automatically. | ||
| 662 | Build output goes to the standard error, and is not shown with | ||
| 663 | B<-q>. If a build fails, the command is not run. With B<-n>, the | ||
| 664 | C<docker build> and C<docker run> commands are shown but nothing is | ||
| 665 | built. | ||
| 666 | |||
| 667 | With B<-L>, a new container is made from the derived image, but an | ||
| 668 | existing container is not changed. B<dozo> warns about it when its | ||
| 669 | image differs; use B<-K> to recreate it: | ||
| 670 | |||
| 671 | dozo -I homebrew/brew --with locale -KL | ||
| 672 | |||
| 673 | Derived images are not removed automatically. They have the labels | ||
| 674 | C<dozo.base> (the base image) and C<dozo.with> (the features applied | ||
| 675 | so far). B<dozo -S> lists them with their state: C<current> (used | ||
| 676 | by B<--with> now), C<outdated> (the feature or the base image has | ||
| 677 | changed since), C<feature gone> or C<base gone>, and shows the | ||
| 678 | commands to remove those not current and not used by a container (see | ||
| 679 | L</Show the status>). To list and remove all of them: | ||
| 680 | |||
| 681 | docker image ls --filter label=dozo.base | ||
| 682 | docker image rm $(docker image ls -q --filter label=dozo.base) | ||
| 683 | |||
| 684 | =head1 CONFIGURATION FILE | ||
| 685 | |||
| 686 | C<.dozorc> files are loaded from the following locations in order: | ||
| 687 | |||
| 688 | =over 4 | ||
| 689 | |||
| 690 | =item 1. Home directory C<.dozorc> | ||
| 691 | |||
| 692 | =item 2. Git top directory C<.dozorc> (if different) | ||
| 693 | |||
| 694 | =item 3. Current directory C<.dozorc> | ||
| 695 | |||
| 696 | =item 4. Command line arguments | ||
| 697 | |||
| 698 | =back | ||
| 699 | |||
| 700 | For single-value options (like C<-I>, C<-N>), later values override | ||
| 701 | earlier ones. For repeatable options (like C<-E>, C<-V>, C<-P>, C<-O>), | ||
| 702 | all values are accumulated in order. | ||
| 703 | |||
| 704 | You can use any command line option in the configuration file: | ||
| 705 | |||
| 706 | # Example .dozorc | ||
| 707 | -I tecolicom/xlate:latest | ||
| 708 | -E CUSTOM_VAR=value | ||
| 709 | -V /data:/data | ||
| 710 | |||
| 711 | Lines starting with C<#> are treated as comments. A C<#> in the middle | ||
| 712 | of a line does B<not> start a comment, and a trailing comment is not | ||
| 713 | supported. | ||
| 714 | |||
| 715 | Each line is split into arguments in the same way as the shell does, so | ||
| 716 | quotation marks have to be balanced. A line which cannot be parsed is | ||
| 717 | an error, and B<Dôzo> stops after showing the file name, the line | ||
| 718 | number and the line itself. | ||
| 719 | |||
| 720 | Write nothing but options in the configuration file. Its contents are | ||
| 721 | placed before the command line arguments, and option parsing stops at | ||
| 722 | the first argument which is not an option. Everything after it, | ||
| 723 | including options given on the command line, is passed to the container | ||
| 724 | as the command to execute. This is the rule which lets you write | ||
| 725 | C<dozo -I alpine ls -la> without C<-la> being taken as an option of | ||
| 726 | B<Dôzo>, but it also means that a stray word in F<.dozorc> disables | ||
| 727 | option parsing altogether. With a trailing comment like this: | ||
| 728 | |||
| 729 | -I alpine # use alpine | ||
| 730 | |||
| 731 | C<dozo -n ls> does not show the docker command line but runs | ||
| 732 | C<# use alpine -n ls> in the container. | ||
| 733 | |||
| 734 | =head1 DOCKER-IN-DOCKER | ||
| 735 | |||
| 736 | To use Docker commands inside the container, mount the host's Docker | ||
| 737 | socket: | ||
| 738 | |||
| 739 | # .dozorc for Docker-in-Docker | ||
| 740 | -I docker | ||
| 741 | -V /var/run/docker.sock | ||
| 742 | |||
| 743 | This allows you to run Docker commands from within the container using | ||
| 744 | the host's Docker daemon: | ||
| 745 | |||
| 746 | $ dozo docker run --rm alpine uname -a | ||
| 747 | |||
| 748 | Or run it as a one-liner without C<.dozorc>: | ||
| 749 | |||
| 750 | $ dozo -I docker -V /var/run/docker.sock docker run --rm alpine uname -a | ||
| 751 | |||
| 752 | =head1 DEFAULT IMAGE | ||
| 753 | |||
| 754 | The C<tecolicom/xlate> image is specifically designed for document | ||
| 755 | translation and text processing tasks, providing a comprehensive | ||
| 756 | environment with the following features: | ||
| 757 | |||
| 758 | =head2 Translation and AI Tools | ||
| 759 | |||
| 760 | =over 4 | ||
| 761 | |||
| 762 | =item * B<DeepL CLI> - Command-line interface for DeepL translation API | ||
| 763 | |||
| 764 | =item * B<gpty> - GPT command-line tool for AI-powered text processing | ||
| 765 | |||
| 766 | =item * B<llm> - Unified LLM interface with plugins for multiple providers: | ||
| 767 | Gemini, Claude 3, Perplexity, and OpenRouter | ||
| 768 | |||
| 769 | =back | ||
| 770 | |||
| 771 | =head2 Text Processing Tools | ||
| 772 | |||
| 773 | =over 4 | ||
| 774 | |||
| 775 | =item * B<greple> with xlate module - Pattern-based text extraction and | ||
| 776 | translation | ||
| 777 | |||
| 778 | =item * B<sdif> - Side-by-side diff viewer with word-level highlighting | ||
| 779 | |||
| 780 | =item * B<ansicolumn>, B<ansifold>, B<ansiexpand> - ANSI-aware text | ||
| 781 | formatting tools | ||
| 782 | |||
| 783 | =item * B<optex textconv> - Document format converter (PDF, Office, etc.) | ||
| 784 | |||
| 785 | =back | ||
| 786 | |||
| 787 | =head2 Greple Extensions | ||
| 788 | |||
| 789 | Multiple L<App::Greple> extension modules are pre-installed: | ||
| 790 | |||
| 791 | =over 4 | ||
| 792 | |||
| 793 | =item * B<msdoc> - Microsoft Office document support | ||
| 794 | |||
| 795 | =item * B<xp> - Extended pattern syntax | ||
| 796 | |||
| 797 | =item * B<subst> - Text substitution with dictionary | ||
| 798 | |||
| 799 | =item * B<frame> - Frame-style output formatting | ||
| 800 | |||
| 801 | =back | ||
| 802 | |||
| 803 | =head2 Git Integration | ||
| 804 | |||
| 805 | The image includes a pre-configured git environment optimized for | ||
| 806 | document comparison and review. Since B<Dôzo> automatically mounts | ||
| 807 | the git top directory by default, git commands work seamlessly with | ||
| 808 | full repository context: | ||
| 809 | |||
| 810 | =over 4 | ||
| 811 | |||
| 812 | =item * B<Side-by-side diff> - C<git diff>, C<git log>, and C<git show> | ||
| 813 | use B<sdif> for word-level side-by-side comparison | ||
| 814 | |||
| 815 | =item * B<Colorful blame> - C<git blame> uses B<greple> for enhanced | ||
| 816 | label coloring | ||
| 817 | |||
| 818 | =item * B<Office document diff> - Compare Word (.docx), Excel (.xlsx), | ||
| 819 | and PowerPoint (.pptx) files directly with git | ||
| 820 | |||
| 821 | =item * B<PDF diff> - View PDF metadata changes | ||
| 822 | |||
| 823 | =item * B<JSON diff> - Normalized JSON comparison using B<jq> | ||
| 824 | |||
| 825 | =back | ||
| 826 | |||
| 827 | =head2 Additional Utilities | ||
| 828 | |||
| 829 | =over 4 | ||
| 830 | |||
| 831 | =item * B<MeCab> - Japanese morphological analyzer with IPA dictionary | ||
| 832 | |||
| 833 | =item * B<poppler-utils> - PDF processing tools (pdftotext, etc.) | ||
| 834 | |||
| 835 | =item * B<jq>, B<yq> - JSON and YAML processors | ||
| 836 | |||
| 837 | =back | ||
| 838 | |||
| 839 | =head2 Environment | ||
| 840 | |||
| 841 | =over 4 | ||
| 842 | |||
| 843 | =item * Based on Ubuntu with Japanese locale (ja_JP.UTF-8) | ||
| 844 | |||
| 845 | =item * Perl and Python3 runtime environments | ||
| 846 | |||
| 847 | =item * Common API keys are automatically inherited from host | ||
| 848 | (DEEPL_AUTH_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.) | ||
| 849 | |||
| 850 | =back | ||
| 851 | |||
| 852 | =head1 ENVIRONMENT | ||
| 853 | |||
| 854 | =head2 Configuration Variables | ||
| 855 | |||
| 856 | =over 4 | ||
| 857 | |||
| 858 | =item C<DOZO_DEFAULT_IMAGE> | ||
| 859 | |||
| 860 | Specifies the default Docker image used when C<-D> (C<--default>) option | ||
| 861 | is given. If not set, C<tecolicom/xlate> is used, which resolves to its | ||
| 862 | C<latest> tag. | ||
| 863 | |||
| 864 | =back | ||
| 865 | |||
| 866 | =head2 Inherited Variables | ||
| 867 | |||
| 868 | The following environment variables are inherited by default: | ||
| 869 | |||
| 870 | LANG TZ | ||
| 871 | HTTP_PROXY HTTPS_PROXY http_proxy https_proxy | ||
| 872 | TERM_PROGRAM TERM_BGCOLOR COLORTERM | ||
| 873 | DEEPL_AUTH_KEY OPENAI_API_KEY ANTHROPIC_API_KEY LLM_PERPLEXITY_KEY | ||
| 874 | |||
| 875 | =head2 Container Variables | ||
| 876 | |||
| 877 | The following environment variables are set inside the container: | ||
| 878 | |||
| 879 | =over 4 | ||
| 880 | |||
| 881 | =item C<DOZO_RUNNING_ON_DOCKER=1> | ||
| 882 | |||
| 883 | Indicates the command is running inside a container started by Dôzo. | ||
| 884 | |||
| 885 | =item C<XLATE_RUNNING_ON_DOCKER=1> | ||
| 886 | |||
| 887 | For compatibility with xlate. Used to prevent recursive Docker | ||
| 888 | invocation when xlate is run inside the container. | ||
| 889 | |||
| 890 | =back | ||
| 891 | |||
| 892 | =head1 SEE ALSO | ||
| 893 | |||
| 894 | L<xlate>, L<App::Greple::xlate> | ||
| 895 | |||
| 896 | L<getoptlong.sh|https://github.com/tecolicom/getoptlong> | ||
| 897 | |||
| 898 | =head1 AUTHOR | ||
| 899 | |||
| 900 | Kazumasa Utashiro | ||
| 901 | |||
| 902 | =head1 LICENSE | ||
| 903 | |||
| 904 | Copyright © 2025-2026 Kazumasa Utashiro. | ||
| 905 | |||
| 906 | This software is released under the MIT License. | ||
| 907 | L<https://opensource.org/licenses/MIT> | ||
| 908 | |||
| 909 | =cut |