Skip to content
GitHubXDiscord

Image

The Image resource allows you to build and manage Docker images from local Dockerfiles using Alchemy.

import * as docker from "alchemy/docker";
const myImage = await docker.Image("app-image", {
name: "my-app",
tag: "v1.0",
build: {
context: "./app"
}
});
NameTypeRequiredDescription
namestringYesDocker image name
tagstringNoTag for the image (defaults to “latest”)
build{ context: string, dockerfile?: string, target?: string, buildArgs?: Record<string, string> }YesBuild configuration
build.contextstringYesPath to the build context (directory containing Dockerfile)
build.dockerfilestringNoPath to the Dockerfile (relative to context, defaults to “Dockerfile”)
build.targetstringNoTarget stage to build in multi-stage Dockerfiles
build.buildArgsRecord<string, string>NoBuild arguments to pass to Docker build
skipPushbooleanNoSkip pushing the image to a registry (default: true)
NameTypeDescription
imageRefstringFull image reference (name:tag)
imageIdstringDocker image ID
createdAtnumberTime when the image was built
import * as docker from "alchemy/docker";
// Build a Docker image from a Dockerfile
const appImage = await docker.Image("app-image", {
name: "my-node-app",
tag: "1.0",
build: {
context: "./app",
dockerfile: "Dockerfile.prod",
buildArgs: {
NODE_ENV: "production",
API_VERSION: "v2"
}
}
});
// Use the built image in a container
const appContainer = await docker.Container("app", {
image: appImage,
ports: [{ external: 3000, internal: 3000 }],
restart: "always",
start: true
});
// For multi-stage builds, you can target a specific stage
const builderImage = await docker.Image("builder", {
name: "app-builder",
tag: "latest",
build: {
context: "./app",
target: "builder" // Target the 'builder' stage in a multi-stage Dockerfile
},
skipPush: true
});