
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
@diagrams-js/plugin-docker-compose
Advanced tools
Docker Compose import/export plugin for diagrams-js
Docker Compose import/export plugin for diagrams-js. Convert between Docker Compose YAML files and architecture diagrams.
npm install @diagrams-js/plugin-docker-compose
import { Diagram } from "diagrams-js";
import { dockerComposePlugin } from "@diagrams-js/plugin-docker-compose";
const diagram = Diagram("My Application");
// Register the plugin
await diagram.registerPlugins([dockerComposePlugin]);
// Import from Docker Compose YAML
const composeYaml = `
version: "3.8"
name: my-app
services:
web:
image: nginx:latest
ports:
- "80:80"
depends_on:
- db
db:
image: postgres:13
environment:
POSTGRES_DB: mydb
`;
await diagram.import(composeYaml, "docker-compose");
// Render the diagram
const svg = await diagram.render();
import { Diagram, Node } from "diagrams-js";
import { dockerComposePlugin } from "@diagrams-js/plugin-docker-compose";
const diagram = Diagram("My Application");
// Create nodes with Docker Compose metadata
const web = diagram.add(Node("web"));
web.metadata = {
compose: {
image: "nginx:latest",
ports: ["80:80"],
},
};
const db = diagram.add(Node("db"));
db.metadata = {
compose: {
image: "postgres:13",
environment: { POSTGRES_DB: "mydb" },
},
};
// Create dependency
web.from(db);
// Register plugin and export
await diagram.registerPlugins([dockerComposePlugin]);
const composeYaml = await diagram.export("docker-compose");
console.log(composeYaml);
// Output:
// version: "3.8"
// name: my-application
// services:
// web:
// image: nginx:latest
// ports:
// - "80:80"
// depends_on:
// - db
// db:
// image: postgres:13
// environment:
// POSTGRES_DB: mydb
depends_on)You can customize which icons are used for specific Docker images. The plugin supports multiple mapping formats:
Mapping Priority:
my-custom-api) - takes precedencenginx, postgres) - fallbackimport { Diagram } from "diagrams-js";
import { createDockerComposePlugin } from "@diagrams-js/plugin-docker-compose";
const diagram = Diagram("My Application");
// Create plugin with custom image mappings
const plugin = createDockerComposePlugin({
imageMappings: {
// 1. Provider icon mapping - use built-in provider icons
"my-custom-api": {
provider: "onprem",
type: "compute",
resource: "Server",
},
"company-db": {
provider: "onprem",
type: "database",
resource: "Postgresql",
},
// 2. Direct URL string - use a custom image URL
"my-frontend": "https://example.com/react-icon.png",
// 3. URL object - same as string but as object
"my-backend": {
url: "https://example.com/node-icon.svg",
},
// 4. Iconify icon - use icons from Iconify (https://iconify.design/)
// Format: { iconify: "prefix:name" }
"docker-service": {
iconify: "logos:docker",
},
"aws-service": {
iconify: "logos:aws",
},
kubernetes: {
iconify: "logos:kubernetes",
},
},
});
await diagram.registerPlugins([plugin]);
ImageMappings TypeExported TypeScript type for defining image mappings with full type safety:
import { createDockerComposePlugin, ImageMappings } from "@diagrams-js/plugin-docker-compose";
const mappings: ImageMappings = {
"my-api": { provider: "onprem", type: "compute", resource: "Server" },
"my-app": { iconify: "logos:docker" },
"custom-service": "https://example.com/icon.svg",
};
const plugin = createDockerComposePlugin({ imageMappings: mappings });
Clusters are created through the diagram instance, not by calling Cluster() directly:
import { Diagram, Node } from "diagrams-js";
import { ECS } from "diagrams-js/aws/compute";
const diagram = Diagram("My Architecture");
// ✅ Correct: Create cluster via diagram.cluster()
const cluster = diagram.cluster("Services");
cluster.add(Node("Web Server"));
cluster.add(ECS("API"));
// Nested clusters
const outer = diagram.cluster("Production");
const inner = outer.cluster("Services");
inner.add(ECS("API"));
// ❌ Incorrect: Don't call Cluster() directly
// const cluster = Cluster("VPC"); // This will throw an error
The Docker Compose plugin automatically creates clusters for each compose project during import.
MIT
FAQs
Docker Compose import/export plugin for diagrams-js
We found that @diagrams-js/plugin-docker-compose demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.