Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
# Dockerfile for a Node.js application # Base image (always start from an existing image) FROM node:18-alpine # Set working directory inside the container WORKDIR /app # Copy package files first (for caching) COPY package*.json ./ # Install dependencies RUN npm ci --only=production # Copy the rest of the application COPY . . # Expose port (documentation only - doesn't publish it) EXPOSE 3000 # Environment variable ENV NODE_ENV=production # Default command to run when container starts CMD ["node", "server.js"] # Build the image: # docker build -t my-node-app . # Run a container from the image: # docker run -d -p 3000:3000 my-node-app
Result
Open