我不是docker的专家,只是在逐渐熟悉。我想将在主机上生成的ssl证书复制到我的docker容器中。我读过可以使用docker-compose文件中的volumes
参数来实现,但在启动服务器时它总是提示无法在工作目录中找到已复制的文件。
文件结构
- repo
- backend
- api
- static
- ssl
- dockerfile
- frontend
- docker-compose.yml
Dockerfile
FROM node:14-alpine
ENV NODE_ENV=production SERVER_PORT_HTTP=80 SERVER_PORT_HTTPS=443
WORKDIR /usr/src/app
RUN npm install
COPY . .
EXPOSE ${SERVER_PORT_HTTP} ${SERVER_PORT_HTTPS}
CMD [ "npm", "run", "start" ]
Docker-Compose
version: "3"
services:
api:
build:
context: ./backend/api
ports:
- "80:80"
- "443:443"
volumes:
- /etc/letsencrypt/live/api.example.com:/static/ssl
restart: unless-stopped
/static/ssl
中查找证书。在我的主机上,我运行一个cronjob将证书更新到/etc/letsencrypt/live/api.example.com
,但它不会将它们复制或链接到容器中。因此,我会得到“Error: ENOENT:没有这样的文件或目录,打开'./static/ssl/privkey.pem'”错误。 - nixn./static/ssl
与根目录下的/static/ssl
不同。尝试将挂载目标更改为/usr/src/app/static/ssl
。 - David Maze