Answer the question
In order to leave comments, you need to log in
How to run a docker container with site statics?
There is a simple Dockerfile that builds the project
FROM node:8
WORKDIR /web
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
RUN yarn build
yarn build
dumps site statics into /web/dist. Answer the question
In order to leave comments, you need to log in
The answer turned out to be much simpler and more beautiful than I expected.
Since version 17.05, docker has such a wonderful thing as Multi-stage build . It allows you to first make a container with nodejs in one dockerfile, build statics in it, and then create another container with nginx, into which to copy the assembly artifacts from the first one. In this case, the resulting image will not contain data from the nodejs image and sources (unless you explicitly copy them in the second step), which allows you to make it as light as possible.
FROM node:8 as build
WORKDIR /web
COPY package.json yarn.lock ./
RUN yarn
COPY . ./
RUN yarn build
FROM nginx:alpine
WORKDIR /usr/share/nginx/html
RUN rm -rf *
COPY --from=build /web/dist .
Try docker-compose.
Here is an example docker-compose.yml file:
version: "3"
services:
my-app:
image: my-app
ports:
- 3000:3000
volumes:
- dist:/web/dist
networks:
- app-network
nginx:
image: nginx
depends_on:
- my-app
ports:
- 80:80
volumes:
- dist:/usr/share/nginx/html
networks:
- app-network
volumes:
dist:
networks:
app-network:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question