Summary
The rewrite-docker module currently only supports Dockerfile transformations. Docker Compose files (compose.yaml, docker-compose.yml) are widely used and would benefit from automated refactoring, security hardening, and modernization recipes.
Since Compose files are YAML, many of these can be declarative (reusing rewrite-yaml building blocks like MergeYaml, DeleteKey, ChangeValue), while others need imperative Java visitors.
1. Migration & Modernization
2. Security Hardening
3. Image Management
4. Health Checks & Reliability
5. Resource Management
6. Network Configuration
7. Volume Management
8. Logging & Observability
9. Environment & Secrets
10. Composite Best-Practice Recipes
Implementation Notes
- File matching: Recipes should target files named
compose.yaml, compose.yml, docker-compose.yaml, docker-compose.yml, and optionally compose.*.yaml (override files), using Preconditions with HasSourcePath glob patterns.
- YAML path selectors: Service-level properties live under
$.services.*.<property>.
- Many recipes are declarative: ~20 can be pure YAML recipe descriptors using existing
rewrite-yaml recipes — no Java code needed.
- Reuse from Dockerfile recipes: Concepts like
FindEndOfLifeImages and NormalizeDockerHubImageName already exist for Dockerfiles; their logic (EOL image lists, normalization rules) can be shared.
Summary
The
rewrite-dockermodule currently only supports Dockerfile transformations. Docker Compose files (compose.yaml,docker-compose.yml) are widely used and would benefit from automated refactoring, security hardening, and modernization recipes.Since Compose files are YAML, many of these can be declarative (reusing
rewrite-yamlbuilding blocks likeMergeYaml,DeleteKey,ChangeValue), while others need imperative Java visitors.1. Migration & Modernization
versionfield (ignored by Compose v2+)docker-compose.yml/docker-compose.yamltocompose.yaml(modern convention)links:with sharednetworks:definitionsvolumes_from:with explicit named volumesdepends_on: [db]to object form withcondition: service_healthymem_limit,memswap_limit,cpu_shares,cpustodeploy.resources.limitsextends(removed in v3) with profiles or anchorscontainer_namewhich is incompatible with Swarm replicationenvironment:list form (- KEY=val) to map form (KEY: val) or vice versa"8080:80") to long-form (target: 80, published: 8080)2. Security Hardening
read_only: trueto servicessecurity_opt: [no-new-privileges:true]to servicescap_drop: [ALL]to servicesuser: "1000:1000"to services that lack auser:directiveprivileged: truefrom services/var/run/docker.sockvolume mountspids_limitto prevent fork bombsipc: hostpid: hostsecurity_opt3. Image Management
image: nginxorimage: nginx:latestwith a specific taglatestor no tagdocker.io/library/prefix for Docker Hub official imagespull_policy: alwaysorpull_policy: if_not_present4. Health Checks & Reliability
healthcheck:block to services that lack onerestart: unless-stopped(oralways) to servicesstop_grace_periodfor graceful shutdowninit: truefor proper PID 1 signal handling5. Resource Management
deploy.resources.limits(memory, cpus) to servicesdeploy.resources.reservations(memory, cpus)ulimits:configuration (nofile, nproc)6. Network Configuration
network_mode: hostfrom servicesbridge,overlay)7. Volume Management
volumes:section:rosuffix to volume mounts that should be read-only/etc,/proc,/sys,/dev8. Logging & Observability
logging:block with driver and options (e.g.,json-filewithmax-size/max-file)9. Environment & Secrets
environment:variables to anenv_file:referenceenvironment:valuessecrets:configuration10. Composite Best-Practice Recipes
AddCapDropAll+AddNoNewPrivileges+AddReadOnlyRootFilesystem+RemovePrivilegedMode+AddNonRootUser+RemoveDockerSocketMountRemoveVersionKey+RenameComposeFile+MigrateLinksToNetworks+MigrateMemLimitToDeployResourcesAddHealthCheck+AddRestartPolicy+AddResourceLimits+AddStopGracePeriod+AddInitTrueImplementation Notes
compose.yaml,compose.yml,docker-compose.yaml,docker-compose.yml, and optionallycompose.*.yaml(override files), usingPreconditionswithHasSourcePathglob patterns.$.services.*.<property>.rewrite-yamlrecipes — no Java code needed.FindEndOfLifeImagesandNormalizeDockerHubImageNamealready exist for Dockerfiles; their logic (EOL image lists, normalization rules) can be shared.