DEV Community

inversemetric
inversemetric

Posted on

Same Dockerfile for Production and Development

You want your servers to run on docker and you want a consistent developer experience locally.

Great!

  1. In your Dockerfile, COPY your source files as normal.
  2. Create a docker-compose.yml file that mounts a volume from the host machine to the source directory (overriding the COPY from the dockerfile). Override the command inside docker-compose.yml as needed.

Build normally for production.
Use docker-compose up --build for development on your host machine.

Example:

Dockerfile

FROM node:alpine
WORKDIR /api
COPY package.json .
COPY yarn.lock .
RUN yarn install
COPY . /api

CMD ["node", "src/index.js"]
Enter fullscreen mode Exit fullscreen mode

docker-compose.yml

version: '3.6'
services:
  api:
    build: .
    volumes:
      - ./src:/api/src
    command: npx nodemon src/index.js
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay