我在将自己签名的SSL / TLS证书放在dockerize nginx服务器上时遇到一些问题。 这是我的nginx.conf
server {
listen 80;
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
这是我的Dockerfile
#==================== Building Stage ================================================
# Create the image based on the official Node 8.9.0 image from Dockerhub
FROM node:8.9.0 as node
# Create a directory where our app will be placed. This might not be necessary
RUN mkdir -p /to-do-app
# Change directory so that our commands run inside this new directory
WORKDIR /to-do-app
# Copy dependency definitions
COPY package.json /to-do-app
# Install dependencies using npm
RUN npm install
# Get all the code needed to run the app
COPY . /to-do-app
COPY certs/nginx-selfsigned.crt /etc/ssl/certs/nginx-selfsigned.crt
COPY certs/nginx-selfsigned.key /etc/ssl/private/nginx-selfsigned.key
COPY nginx-to-do-app.conf /etc/nginx/conf.d/default-ssl.conf
# Expose the port the app runs in
EXPOSE 4200
#Build the app
RUN npm run build
#==================== Setting up stage ====================
# Create image based on the official nginx - Alpine image
FROM nginx:1.13.7-alpine
COPY --from=node /to-do-app/dist/ /usr/share/nginx/html
COPY ./nginx-to-do-app.conf /etc/nginx/conf.d/default.conf
我可以使用
成功创建图像docker build . -t myimage
但是,如果我尝试使用创建容器
docker run -p 80:80 myimage
我遇到以下错误
2018/07/05 14:08:05 [emerg] 1#1: BIO_new_file("/etc/ssl/certs/nginx-selfsigned.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/ssl/certs/nginx-selfsigned.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: [emerg] BIO_new_file("/etc/ssl/certs/nginx-selfsigned.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/ssl/certs/nginx-selfsigned.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
我在Windows 10上使用Docker版本18.03.1-ce,构建9ee9f40的Powershell(但在git bash中有相同的错误)