[GH-ISSUE #164] Add Docker #65

Closed
opened 2026-03-16 13:07:43 +03:00 by kerem · 14 comments
Owner

Originally created by @jgroom33 on GitHub (Sep 25, 2019).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/164

it would be nice to have no install dependencies except docker.

expected behavior: docker run -it -p 3000:3000 liyasthomas/postwoman:latest

Originally created by @jgroom33 on GitHub (Sep 25, 2019). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/164 it would be nice to have no install dependencies except docker. expected behavior: `docker run -it -p 3000:3000 liyasthomas/postwoman:latest`
kerem 2026-03-16 13:07:43 +03:00
  • closed this issue
  • added the
    feature
    label
Author
Owner

@jgroom33 commented on GitHub (Sep 25, 2019):

@liyasthomas
“Set up Automated Builds using GitHub and Docker Hub” by oleksii_y https://link.medium.com/AmD5s8x6f0

<!-- gh-comment-id:534820740 --> @jgroom33 commented on GitHub (Sep 25, 2019): @liyasthomas “Set up Automated Builds using GitHub and Docker Hub” by oleksii_y https://link.medium.com/AmD5s8x6f0
Author
Owner

@liyasthomas commented on GitHub (Sep 25, 2019):

We're already making use of Travis CI for deployments. And I'm not experienced with docker. Would you care to explain docker CD advantages over other CIs?

<!-- gh-comment-id:534826660 --> @liyasthomas commented on GitHub (Sep 25, 2019): We're already making use of Travis CI for deployments. And I'm not experienced with docker. Would you care to explain docker CD advantages over other CIs?
Author
Owner

@jgroom33 commented on GitHub (Sep 25, 2019):

the requirement is:
Publish an image to docker hub liyasthomas/postwoman

This account needs to exist so the image can be published there.

Then the image needs to be pushed there.

It's probably possible to do this with Travis, but it would require that to be setup in Travis. (Ie add a token for docker hub in Travis)

If docker hub is used, the process is easier. Just link your GitHub account from docker hub and it will watch for new releases. When a new release is published, it builds the image using the docker file and publishes it.

<!-- gh-comment-id:534827826 --> @jgroom33 commented on GitHub (Sep 25, 2019): the requirement is: Publish an image to docker hub liyasthomas/postwoman This account needs to exist so the image can be published there. Then the image needs to be pushed there. It's probably possible to do this with Travis, but it would require that to be setup in Travis. (Ie add a token for docker hub in Travis) If docker hub is used, the process is easier. Just link your GitHub account from docker hub and it will watch for new releases. When a new release is published, it builds the image using the docker file and publishes it.
Author
Owner

@liyasthomas commented on GitHub (Sep 25, 2019):

Cool! Let me do a background check on it and will let you know.

<!-- gh-comment-id:534828187 --> @liyasthomas commented on GitHub (Sep 25, 2019): Cool! Let me do a background check on it and will let you know.
Author
Owner

@liyasthomas commented on GitHub (Sep 25, 2019):

Closed by accident

<!-- gh-comment-id:534828237 --> @liyasthomas commented on GitHub (Sep 25, 2019): Closed by accident
Author
Owner

@liyasthomas commented on GitHub (Sep 26, 2019):

@jgroom33
https://hub.docker.com/r/liyasthomas/postwoman
docker pull liyasthomas/postwoman

<!-- gh-comment-id:535470307 --> @liyasthomas commented on GitHub (Sep 26, 2019): @jgroom33 https://hub.docker.com/r/liyasthomas/postwoman `docker pull liyasthomas/postwoman`
Author
Owner

@jgroom33 commented on GitHub (Sep 26, 2019):

Works great. Now just need to update the readme with:
docker run -p 3000:3000 liyasthomas/postwoman:latest

<!-- gh-comment-id:535700218 --> @jgroom33 commented on GitHub (Sep 26, 2019): Works great. Now just need to update the readme with: `docker run -p 3000:3000 liyasthomas/postwoman:latest`
Author
Owner

@liyasthomas commented on GitHub (Sep 26, 2019):

Will do

<!-- gh-comment-id:535701324 --> @liyasthomas commented on GitHub (Sep 26, 2019): Will do
Author
Owner

@liyasthomas commented on GitHub (Sep 27, 2019):

@jgroom33 can you tell me why docker taking ~12 mins to build? Any optimizations you wanna suggest to dockerfile?

<!-- gh-comment-id:535774690 --> @liyasthomas commented on GitHub (Sep 27, 2019): @jgroom33 can you tell me why docker taking ~12 mins to build? Any optimizations you wanna suggest to `dockerfile`?
Author
Owner

@jgroom33 commented on GitHub (Sep 27, 2019):

Where are you seeing the 12 minutes?
One of the things that would be good is to use an alpine image. They are much smaller (50M compared to 300M)
But that would only impact time if the root image is being downloaded each build.
I tried to use an alpine image originally, but the build failed.

<!-- gh-comment-id:535827291 --> @jgroom33 commented on GitHub (Sep 27, 2019): Where are you seeing the 12 minutes? One of the things that would be good is to use an alpine image. They are much smaller (50M compared to 300M) But that would only impact time if the root image is being downloaded each build. I tried to use an alpine image originally, but the build failed.
Author
Owner

@liyasthomas commented on GitHub (Sep 27, 2019):

Build duration was 12 mins.
Let me see if I could build with alpine rather than buster.

<!-- gh-comment-id:535834616 --> @liyasthomas commented on GitHub (Sep 27, 2019): Build duration was 12 mins. Let me see if I could build with alpine rather than buster.
Author
Owner

@jgroom33 commented on GitHub (Sep 27, 2019):

https://hub.docker.com/_/node/?tab=tags&page=1&name=alpine

<!-- gh-comment-id:535937138 --> @jgroom33 commented on GitHub (Sep 27, 2019): https://hub.docker.com/_/node/?tab=tags&page=1&name=alpine
Author
Owner

@jls-tschanzc commented on GitHub (Dec 2, 2019):

Another improvement might be to use tini and switching from "npm run start" to directly executing the nuxt command. Just add "tini" to the apk add command and then switch the CMD line with:

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["nuxt", "start"]

Another nice to have feature might be a healthcheck, something like this:

HEALTHCHECK --interval=5m --timeout=3s CMD curl --fail http://localhost:3000/health || exit 1

I am not entirely sure how nuxt works and what dependencies it needs for runtime but maybe it could further slim down the resulting image by using a multi stage build so you would prepare everything for the npm run build in the first stage and run the build and then in the second stage you would only copy over the resulting build artefacts and set ENV NODE_ENV production as well as run only npm install --only=prod (IF all the dependencies are even required for nuxt to run).

<!-- gh-comment-id:560318018 --> @jls-tschanzc commented on GitHub (Dec 2, 2019): Another improvement might be to use [tini](https://github.com/krallin/tini) and switching from "npm run start" to directly executing the nuxt command. Just add "tini" to the `apk add` command and then switch the CMD line with: ``` ENTRYPOINT ["/sbin/tini", "--"] CMD ["nuxt", "start"] ``` Another nice to have feature might be a [healthcheck](https://docs.docker.com/engine/reference/builder/#healthcheck), something like this: ``` HEALTHCHECK --interval=5m --timeout=3s CMD curl --fail http://localhost:3000/health || exit 1 ``` I am not entirely sure how nuxt works and what dependencies it needs for runtime but maybe it could further slim down the resulting image by using a [multi stage build](https://docs.docker.com/develop/develop-images/multistage-build/) so you would prepare everything for the `npm run build` in the first stage and run the build and then in the second stage you would only copy over the resulting build artefacts and set `ENV NODE_ENV production` as well as run only `npm install --only=prod` (IF all the `dependencies` are even required for nuxt to run).
Author
Owner

@pidario commented on GitHub (Jan 13, 2020):

Sorry to comment under a closed issue, but in response to the previous comment I tried this Dockerfile:

FROM node:12.10.0-alpine as builder

WORKDIR /app

# Add git as the prebuild target requires it to parse version information
RUN apk add --update --no-cache \
  git \
  tini \
  ca-certificates

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build
######################################################################################
FROM node:12.10.0-alpine as runner

LABEL maintainer="Liyas Thomas (liyascthomas@gmail.com)"

COPY --from=builder /sbin/tini /sbin/tini
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

WORKDIR /app

COPY --from=builder /app .

EXPOSE 3000

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["node_modules/.bin/nuxt", "start"]

I added tini as suggested and I also took the liberty to add ca-certificates.

I usually build this Dockerfile by using two different commands in sequence:
docker build --target builder -t builder-postwoman:latest .
This image is used for caching purposes only and is not pushed to docker hub: note the tag is just builder-postwoman;
and then
docker build --target runner -t liyasthomas/postwoman:latest .
This one instead has the usual tag you currently use and will be pushed to DH.

The image got shrunk down to 303MB, which is not bad for a nodejs application this large but probably you could still improve it by installing production dependencies only (for example you don't need test suite in production) as suggested by @jls-tschanzc

<!-- gh-comment-id:573686611 --> @pidario commented on GitHub (Jan 13, 2020): Sorry to comment under a closed issue, but in response to the previous comment I tried this Dockerfile: ``` FROM node:12.10.0-alpine as builder WORKDIR /app # Add git as the prebuild target requires it to parse version information RUN apk add --update --no-cache \ git \ tini \ ca-certificates COPY package*.json ./ RUN npm install COPY . . RUN npm run build ###################################################################################### FROM node:12.10.0-alpine as runner LABEL maintainer="Liyas Thomas (liyascthomas@gmail.com)" COPY --from=builder /sbin/tini /sbin/tini COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt WORKDIR /app COPY --from=builder /app . EXPOSE 3000 ENTRYPOINT ["/sbin/tini", "--"] CMD ["node_modules/.bin/nuxt", "start"] ``` I added tini as suggested and I also took the liberty to add ca-certificates. I usually build this Dockerfile by using two different commands in sequence: `docker build --target builder -t builder-postwoman:latest .` This image is used for caching purposes only and is not pushed to docker hub: note the tag is just builder-postwoman; and then `docker build --target runner -t liyasthomas/postwoman:latest .` This one instead has the usual tag you currently use and will be pushed to DH. The image got shrunk down to 303MB, which is not bad for a nodejs application this large but probably you could still improve it by installing production dependencies only (for example you don't need test suite in production) as suggested by @jls-tschanzc
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#65
No description provided.