This repository provides an example of using Docker volumes with a Node.js application. It demonstrates how to use Docker volumes to persist data and share files between a host and a Docker container, which is useful for developers looking to manage data in a containerized environment.
- Node.js
- Docker
- Yarn or npm for package management
- Clone the repository:
git clone https://github.com/ferrerallan/docker-volume-example.git
- Navigate to the project directory:
cd docker-volume-example - Ensure you have Docker installed on your machine.
- Build the Docker image:
docker build -t docker-volume-example . - Run the Docker container with a volume:
docker run -d -p 3000:3000 -v /host/path:/container/path docker-volume-example
- Dockerfile: Contains instructions for building the Docker image.
- src/: Contains the Node.js application source code.
Here is an example of a simple Dockerfile for a Node.js application that uses volumes:
# Use the official Node.js image as a base
FROM node:14
# Set the working directory
WORKDIR /usr/src/app
# Copy package.json and package-lock.json files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Expose the application port
EXPOSE 3000
# Command to run the application
CMD ["node", "app.js"]This Dockerfile sets up a Node.js application environment, installs dependencies, and runs the application. Docker volumes can be used to persist data and share files between the host and container.
This project is licensed under the MIT License.
You can access the repository here.