moon docker command provides a suite of sub-commands for working with Docker in your moon
workspace. These commands help you generate optimized Dockerfiles, scaffold repository skeletons for
efficient layer caching, and manage dependencies within Docker containers.
:::info
View the official Docker usage guide for a comprehensive guide on using Docker
with moon.
:::
Sub-commands
moon docker file
Generate a multi-staged Dockerfile for a project that takes full advantage of Docker’s layer
caching. This is primarily for production deploys.
Dockerfile uses a multi-stage approach:
base- Installs moon for the chosen Docker image (requires Bash)skeleton- Scaffolds workspace and sources usingmoon docker scaffoldbuild- Copies sources, installs toolchain viamoon docker setup, builds the project, and optionally prunes usingmoon docker prunestart- Runs the project (typically starting a server or executing a binary)
Arguments
<id>- Project ID or alias to create a Dockerfile for[dest]- Destination path, relative from the project root. Defaults toDockerfile
Options
--defaults- Use default options instead of prompting--build-task- ID of a task to build the project--image- Base Docker image to use--no-prune- Do not prune dependencies in the build stage--no-setup- Do not setup dependencies in the build stage--no-toolchain- Do not use the toolchain and instead use system binaries--start-task- ID of a task to run the project--template- Template path, relative from workspace root, to render the Dockerfile with
moon docker scaffold
Create multiple repository skeletons for use within Dockerfiles to effectively take advantage of
Docker’s layer caching. Uses the project graph to copy only critical files like manifests,
lockfiles, and configuration.
.moon/docker (be sure to gitignore this):
- configs - Mirrors the project folder structure 1:1, copying only files required for
dependencies to install (manifests, lockfiles, configs,
.moondirectory) - sources - Contains source files of the specified project(s) and all their dependencies
Arguments
<...ids>- List of project IDs to copy sources for
moon docker setup
Setup a Dockerfile by installing toolchains and dependencies for necessary projects. This command
reads from a dockerManifest.json file created by moon docker scaffold.
- Reads the
dockerManifest.jsonfrom the workspace root - Installs toolchains for all focused projects
- Installs dependencies for all focused projects
Dockerfile in the build stage.
:::
moon docker prune
Remove extraneous dependencies within a Dockerfile to reduce the final image size. This removes
development dependencies and other artifacts not needed for production.
- Reads the
dockerManifest.jsonfrom the workspace root - Locates dependency workspaces for focused projects
- Prunes development dependencies
- Optionally reinstalls only production dependencies
Dockerfile in the build stage after building the project.
:::
Configuration
docker.filein.moon/workspace.*(forfilecommand)docker.fileinmoon.*(forfilecommand)docker.scaffoldin.moon/workspace.*(forscaffoldcommand)docker.scaffoldinmoon.*(forscaffoldcommand)docker.prunein.moon/workspace.*(forprunecommand)
Example Dockerfile
Here’s an example of a generated multi-stageDockerfile: