docker-frame-tool

1.1.1 • Public • Published

docker-frame-tool

1. What This Does

The Docker Frame Tool is a command-line interface (CLI) utility that automates the process of creating Docker configurations for Node.js applications. It simplifies the creation of Dockerfiles, Docker Compose files, and the setup of container ports, image names, and run commands. It supports setting up containers with or without nodemon, allowing you to easily run Node.js applications with live-reloading capabilities inside Docker.

This tool makes Docker integration for Node.js apps easy, enabling you to:

  • Automatically generate Dockerfiles
  • Create a Docker Compose setup
  • Configure port mappings
  • Mount local files for live reloading with nodemon (optional)


2. Installation

The Docker Frame Tool can be used directly with npx, so there is no need to install it globally. Simply run the following command to use it:

  npx docker-frame-tool

This will trigger the tool to start asking you for the necessary configuration details, such as the project name, Node.js version, and whether you want to use nodemon.



3. Usage/Examples

1. Run the CLI Command:

To begin setting up Docker configurations for your Node.js project, simply run:

    npx docker-frame-tool

2. Answer the Prompts:

The tool will ask a series of questions to configure the Docker environment:

  • Image/Container Name: The name of your Docker image and container (based on your project folder name).
  • Node Version: The Node.js version for your Docker container.
  • Project Type: The type of project (currently only supports Node App)
  • Port Information: Choose the port your app will run on and the type of container port.
  • Use of Nodemon: Choose whether to mount local files and use nodemon for live reloading inside the container.

3. Docker Setup:

After answering the questions, the tool will automatically generate:

  • A Dockerfile
  • A docker-compose.yml file
  • A .dockerignore file
  • Scripts added to package.json for building and running the Docker container

4. commands in package.json:

For a Simple Node Application If you configured your project without nodemon:

# Build the Docker container
npm run docker:build

# Run the Docker container in detached mode (stops when closed)
npm run docker:container

# Build and run the Docker container (not detached)
npm run docker:run

For a Node Application with Nodemon

# Start nodemon for local development
npm run dev

# Build the Docker container
npm run docker:build

# Run the Docker container in detached mode (stops when closed)
npm run docker:container

# Build and run the Docker container (not detached)
npm run docker:run

# Build and run the Docker container with volume mounting (for live reloading)
npm run docker:volume


4. Configuration Options

Dockerfile Configuration

The Dockerfile is generated based on your input and will either include nodemon or not. The key configurations are:

1. Standard Node.js App

A basic Dockerfile will be created for your app, including the necessary commands to install dependencies and run your application.

Example Dockerfile for a regular Node.js app:

FROM node:12
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 8080
CMD ["node", "index.js"]

2. Node.js App with Nodemon:

If you choose to use nodemon, a different Dockerfile is generated that installs nodemon globally and runs your application using the dev script. Example Dockerfile for a Node.js app with nodemon:

FROM node:12
RUN npm i -g nodemon
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 8080
CMD ["npm", "run", "dev"]

docker-compose.yml Configuration

The docker-compose.yml file is generated to define how the Docker container is built and run. There are two possible configurations for the Compose file depending on whether you choose to use nodemon:

1. Standard Node.js App (without Nodemon):

version: '3.8'
services:
  node-app:
    build:
      context: .
    image: my-node-app
    container_name: my-node-app
    working_dir: /app
    command: ["node", "index.js"]
    ports:
      - "8080:8080"

1. Node.js App with Nodemon (with Nodemon):

version: '3.8'
services:
  image_and_container:
    build:
      context: .
      dockerfile: Dockerfile
    image: my-node-app
    container_name: my-node-app
    command: ["node", "index.js"]
    ports:
      - "8080:8080"

  container_with_volume:
    build:
      context: .
    image: my-node-app
    container_name: my-node-app
    volumes:
      - .:/app
      - /app/node_modules
    command: ["npm", "run", "dev"]
    ports:
      - "8080:8080"

The container_with_volume section allows you to mount your local files into the container and use nodemon for auto-reloading when changes are made to the files.



5. Troubleshooting Common Issues

1. Docker is not installed:

If the tool detects that Docker is not installed, you will see a message like:

Docker is not installed or not found in the system path.

Make sure Docker is installed and running on your system. You can install Docker from Docker's official website

2. Missing package.json:

If your project does not have a package.json file, the tool will inform you:

package.json not found in the current directory.

Make sure your project is a Node.js project with a valid package.json file before running the tool.

3. Invalid Docker Commands:

If the tool fails to create the Docker configuration correctly, ensure that your project files are properly set up. The tool assumes that your project contains a package.json with a valid main entry or defaults to index.js.

4. Permissions Errors:

If you encounter permission errors when creating files, try running the tool with elevated permissions (e.g., sudo on Linux/macOS):

sudo npx docker-frame-tool



## License This project is licensed under the ISC License. You can freely use, modify, and distribute the software, but with no warranty, and the code is provided as-is.

Dependents (0)

Package Sidebar

Install

npm i docker-frame-tool

Weekly Downloads

0

Version

1.1.1

License

Apache-2.0

Unpacked Size

33.5 kB

Total Files

16

Last publish

Collaborators

  • dhruv_seth