Skip to content

Context

Source: src/Docker/Context.ts

A named Docker CLI context — a pointer to a Docker engine (local socket, SSH host, or TCP endpoint) that other Docker resources deploy through.

Pass the context (or its name) to any Docker resource’s context prop to run that resource’s operations against the referenced engine instead of the default one. Changing the endpoint updates the context in place; renaming it, or clearing a previously-set endpoint, replaces it.

const vps = yield* Docker.Context("vps", {
docker: "host=ssh://deploy@example.com",
description: "production swarm manager",
});

Deploy resources through the context

const vps = yield* Docker.Context("vps", {
docker: "host=ssh://deploy@example.com",
});
const network = yield* Docker.Network("app-net", {
context: vps,
driver: "overlay",
});
const app = yield* Docker.Service("app", {
context: vps,
image: "nginx:alpine",
networks: [network.name],
});

Local development vs production

const dev = yield* Alchemy.ALCHEMY_DEV;
const context = yield* Docker.Context("target", {
name: dev ? "local" : "vps",
docker: dev ? undefined : "host=ssh://deploy@example.com",
});