Skip to content

Simple implementation of Docker for development and production #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/node_modules
/docker

npm-debug.log*
yarn-debug.log*
yarn-error.log*

.vercel
.gitignore
.github
.next
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
build-development:
docker-compose -f docker/docker-compose.dev.yml build --no-cache

run-development:
docker-compose -f docker/docker-compose.dev.yml up -d

stop-development:
docker-compose -f docker/docker-compose.dev.yml down

build-production:
docker-compose -f docker/docker-compose.prod.yml build --no-cache

run-production:
docker-compose -f docker/docker-compose.prod.yml up -d

stop-production:
docker-compose -f docker/docker-compose.prod.yml down
11 changes: 11 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:14-alpine
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using a slim image instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using a slim image instead.

Apart of the size and the distro, what's the difference between alpine and slim?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's not much. It's mostly the same, except Alpine is a completely separate distro of it's own.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, for development has sense to use slim because being a debian distro there are chances to install any additional package with apt, as for production I prefer to keep it with alpine since the smaller the image the better


WORKDIR /app

COPY package*.json yarn.lock* ./

RUN yarn

COPY ./ ./

CMD ["yarn", "dev"]
13 changes: 13 additions & 0 deletions docker/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:14-alpine

WORKDIR /app

COPY package*.json yarn.lock* ./

RUN yarn

COPY ./ ./

RUN yarn build

CMD ["yarn", "start"]
13 changes: 13 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:
app:
container_name: hacktoberfest_projects_dev
build:
context: ../
dockerfile: docker/Dockerfile.dev
ports:
- 3000:3000
volumes:
- ../:/app
- /app/node_modules
10 changes: 10 additions & 0 deletions docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.8'

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try adding restart: on-failure for cases when it fails

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try adding restart: on-failure for cases when it fails

I've added the restart property for production, before I've added it for development too but now I've removed it

services:
app:
container_name: hacktoberfest_projects_prod
build:
context: ../
dockerfile: docker/Dockerfile.prod
ports:
- 3000:3000