Dockmate is a versatile CLI tool designed to simplify Docker workflows for JavaScript-based projects. It streamlines tasks like generating Dockerfiles, building Docker images, and running containers. With support for frameworks such as React, Angular, Next.js, Vue.js, and more, Dockmate is your go-to helper for containerizing applications effortlessly.
npm i dockmate
OR If dockmate doesn't work then install it globally.
npm i -g dockmate
- Framework Detection: Automatically detects the framework of your project and generates a tailored Dockerfile.
- Interactive UI: Step-by-step guided Dockerfile creation for users new to Docker.
- Custom Dockerfile Generation: Supports React, Angular, Node.js, Next.js, Vue.js, and other major JavaScript frameworks.
- Live Dockerfile Generation: Supports on fly Dockerfile generation. It checks changes in the repository and generates Dockerfile.
- Docker Image Management: Build Docker images directly from your projectβs Dockerfile or generate one if missing.
- Container Management: Easily run Docker containers with custom configurations for ports, environment variables, and more.
- Extensibility: Plugin architecture allows adding new features effortlessly.
Dockmate offers several commands to manage Docker workflows. Below is a list of commands, their descriptions, and example outputs:
Guides you through an interactive setup to generate a Dockerfile.
dockmate init
? What framework does your project use? (Use arrow keys)
react
angular
vuejs
nextjs
node
? What port does your application listen on? 3000
? What is the entry point for your application? index.js
? What version of Node.js should be used? 18
? Does your project use a .env file? Yes
? Do you want to take backup of the Dockerfile? Yes
? Do you want to preview the Dockerfile content? Yes
--- Dockerfile Preview ---
## DOCKERFILE CONTENT
? Do you want to save this Dockerfile? Yes
[INFO] Dockerfile created successfully!
Automatically generates a Dockerfile based on project dependencies.
dockmate generate
--framework
Specify the framework (react, angular, node, nextjs, vuejs, sevelte, gatsby).--nodeVersion
Specify Node.js version (default: 18).--port
Specify application port (default: 3000).--entryPoint
Specify entry point file (default: index.js).--preview
Specify to Preview the Dockerfile content or not (default: false).--backup
Specify whether to backup the Dockerfile (default: false).
dockmate generate --framework=node --nodeVersion=16 --port=4000 --entryPoint=app.js --preview
[INFO] Generating Dockerfile for node...
[INFO] Dockerfile created successfully!
You can take backup of your dockerfiles under /.dockmate/backups directory.
dockmate backup
[INFO] Backup saved: /yourpath/.dockmate/backups/Dockerfile-2025-01-07T10-28-11-145Z.bak
This will restore the Dockerfile to its latest or specific Dockerfile backup.
dockmate undo
// OR
dockmate undo Dockerfile-2025-01-07T10-28-11-145Z.bak
[INFO] Restored backup: /yourpath/.dockmate/backups/Dockerfile-2025-01-07T10-28-11-145Z.bak
This will delete the Backup files from /.dockmate/backups/ directory
dockmate delete-backups
Builds a Docker image for your project.
dockmate build
--tag
Specify image tag (default: latest).--framework
Specify framework for the Dockerfile.--dockerfilePresent
Indicate if the Dockerfile is already present (default: true).--name
Specify Docker image name (default: dockmate-image-).
dockmate build --tag=myapp:1.0 --framework=react --name=myapp-image
[INFO] Building Docker image with tag: myapp:1.0...
[INFO] Docker image built successfully!
dockmate run --image=<imageName>
--port
Specify port mapping (host:container format).--env
Set environment variables (KEY=value format).--name
Specify container name.
dockmate run --image=myapp:1.0 --port=8080:3000 --env=NODE_ENV=production --name=myapp-container
[INFO] Starting container myapp-container...
[INFO] Container started successfully!
dockmate dev
? Enter the files or directories to watch: ./src, ./index.js
? Enter the path to the Dockerfile: ./Dockerfile
? Enter the Docker image name: dockmate-dev
? Enter the name of the Docker container: dockmate-dev-container
? Should the container restart automatically on changes? Yes
[INFO] Development mode started. Watching files for changes...
Dockmate provides several utility functions that can be integrated into your projects. Below is a structured way to use them programmatically:
Automatically detect the framework your project uses.
// import module
const { detectFramework } = require('dockmate');
// detect the framework of the working project
(async () => {
try {
const framework = await detectFramework();
console.log(`Detected Framework: ${framework}`);
} catch (error) {
console.error(`[ERROR] Framework detection failed: ${error.message}`);
}
})();
Generate a Dockerfile for your project based on options.
// import module
const { generateDockerfile } = require('dockmate');
// generate the dockerfile based on the framework and options
(async () => {
try {
const options = {
nodeVersion: '18', // Node.js version
port: 3000, // Application port
entryPoint: 'index.js', // Application entry point
useEnv: true, // Whether to include .env file
};
await generateDockerfile('react', options);
console.log('[INFO] Dockerfile created successfully!');
} catch (error) {
console.error(`[ERROR] Dockerfile generation failed: ${error.message}`);
}
})();
Build a Docker image for your project.
// import module
const { buildImage } = require('dockmate');
// build docker image using the options
(async () => {
try {
const options = {
tag: 'myapp:1.0', // Image tag
framework: 'react', // Framework used
dockerfilePresent: true, // Whether Dockerfile already exists
imageName: 'myapp-image', // Image name
};
await buildImage(options);
console.log('[INFO] Docker image built successfully!');
} catch (error) {
console.error(`[ERROR] Image build failed: ${error.message}`);
}
})();
Run a Docker container from an image with customizable options.
// import module
const { runContainer } = require('dockmate');
// runContainer using options
(async () => {
try {
const options = {
imageName: 'myapp:1.0', // Image name
ports: [{ host: 8080, container: 3000 }], // Port mapping
env: { NODE_ENV: 'production' }, // Environment variables
containerName: 'myapp-container', // Name of the container
};
await runContainer(options);
console.log('[INFO] Docker container started successfully!');
} catch (error) {
console.error(`[ERROR] Container start failed: ${error.message}`);
}
})();
Run a Docker container in development mode with live reload for specified paths.
// import module
const { startDevMode } = require('dockmate');
// use options to start the dev mode
(async () => {
try {
const options = {
watchPaths: ['./src', './index.js'], // Files or directories to watch
dockerfilePath: './Dockerfile', // Path to Dockerfile
imageName: 'dev-image', // Image name for development
containerName: 'dev-container', // Container name
autoRestart: true, // Auto-restart on changes
};
await startDevMode(options);
console.log('[INFO] Development mode started. Watching for changes...');
} catch (error) {
console.error(`[ERROR] Development mode failed: ${error.message}`);
}
})();
Again prefer using dockmate CLI
Contributions are welcome! Hereβs how you can help, read the Contribution-guide.md file. Feel free to report bugs or suggest new features by opening an issue.
This project is licensed under the MIT License. See the LICENSE file for details.
Big thanks to the open-source community for inspiration and support. Letβs build something amazing together!
Happy coding! π