将清漆添加到现有节点 Dockerfile

Adding varnish to existing node Dockerfile

我有以下 Dockerfile

FROM node:10-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY package*.json ./
USER node
RUN npm install
COPY --chown=node:node . .
EXPOSE 8080
CMD [ "node", "app.js" ]

现在我想添加 Varnish 缓存并考虑这个 repo docker-varnish我如何将两者组织在一起?

更新 1

一旦我运行这个命令docker compose build它显示了以下信息,但我没有看到任何与清漆相关的东西

[+] Building 4.6s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 362B 0.0s => [internal] load .dockerignore 0.1s => => transferring context: 174B 0.0s => [internal] load metadata for docker.io/library/node:10-alpine 4.0s => [internal] load build context 0.1s => => transferring context: 21.58kB 0.0s => [1/6] FROM docker.io/library/node:10-alpine@sha256:dc98dac24efd4254f75976c40bce46944697a110d06ce7fa47e7268470cf2e28 0.0s => CACHED [2/6] RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
0.0s => CACHED [3/6] WORKDIR /home/node/app 0.0s => CACHED [4/6] COPY package*.json ./ 0.0s => CACHED [5/6] RUN npm install 0.0s => [6/6] COPY --chown=node:node . . 0.1s => exporting to image 0.1s => => exporting layers 0.0s => => writing image sha256:7eec4ec76dbff93f8b0ebc6e03051331709d5f55a641be379a3e00697eabde70 0.0s => => naming to docker.io/library/test_project_node

我做的对吗?

您可以使用 docker compose 编排多个容器,如下所述:https://www.varnish-software.com/developers/tutorials/running-varnish-docker/#6-docker-compose .

这使用官方 Varnish 图像,而不是您建议的图像。

下面是 docker compose 命令使用的 docker-compose.yml 文件的示例:

version: "3"
services:
  varnish:
    image: varnish:stable
    container_name: varnish
    volumes:
      - "./default.vcl:/etc/varnish/default.vcl"
    ports:
      - "80:80"
    tmpfs:
      - /var/lib/varnish:exec
    environment:
      - VARNISH_SIZE=2G  
    depends_on:
      - "node" 
  node:
    build: ./
    container_name: node
    ports:
      - "8080:8080"

docker-compose.yml 文件假定它与您的节点容器的 Dockerfile 位于同一文件夹中。它还假定 default.vcl 也位于该文件夹中。

运行 docker compose up 到 bootstrap 堆栈。