[英]build with volumes in the docker-compose.yml
I want to run multiple web application images with NGINX. 我想使用NGINX运行多个Web应用程序映像。
So I wrote docker-compose.yml
which build nginx image and run nodejs containers. 所以我写了
docker-compose.yml
来构建nginx图像并运行nodejs容器。
I have SSL Certificate issued by letsencrypt. 我有letencrypt颁发的SSL证书。
The certificate files is located in /etc/letsencrypt/live/mydomain.com/
证书文件位于
/etc/letsencrypt/live/mydomain.com/
I want NGINX container to read the files. 我希望NGINX容器读取文件。
So, I appended volumes: - /etc/letsencrypt/live/mydomain.com/:/etc/cert:ro
to docker-compose.yml
. 因此,我将
volumes: - /etc/letsencrypt/live/mydomain.com/:/etc/cert:ro
附加volumes: - /etc/letsencrypt/live/mydomain.com/:/etc/cert:ro
docker-compose.yml
volumes: - /etc/letsencrypt/live/mydomain.com/:/etc/cert:ro
docker-compose.yml
volumes: - /etc/letsencrypt/live/mydomain.com/:/etc/cert:ro
docker-compose.yml
volumes: - /etc/letsencrypt/live/mydomain.com/:/etc/cert:ro
至docker-compose.yml
。
But nginx.conf cannot read the files. 但是nginx.conf无法读取文件。
I found that the directory /etc/cert
doesn't exist and it's mounted as bind type. 我发现目录
/etc/cert
不存在,并且已作为绑定类型挂载。
I want to know how to set volumes in the docker-compose.yml file to read inside of containers. 我想知道如何在docker-compose.yml文件中设置卷以读取容器内部。
docker-compose.yml docker-compose.yml
version: '2.0'
services:
nginx:
container_name: manager
build: ./nginx
links:
- app-1:app-1
...
ports:
- 80:80
- 443:443
volumes:
- /etc/letsencrypt/live/mydomain.com/:/etc/cert:ro
depends_on:
- app-1
...
app-1:
container_name: audio-1
image: audio:test
ports:
- 80
...
nginx.conf nginx.conf
worker_processes 4;
events { worker_connections 1024; }
http {
upstream node-app {
least_conn;
server app-1:80 weight=10 max_fails=3 fail_timeout=60s;
...
}
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/cert/fullchain.pem;
ssl_certificate_key /etc/cert/privkey.pem;
location / {
proxy_pass http://node-app;
...
}
}
}
error 错误
nginx: [emerg] BIO_new_file("/etc/cert/fullchain.pem") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/cert/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)
$docker inspect manager $ docker检查经理
...
"Mounts": [
{
"Type": "bind",
"Source": "/etc/letsencrypt/live/luvber.kr",
"Destination": "/etc/cert",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
}
],
...
Thanks 谢谢
The problem is that the volume would be mounted after the build operations is completed. 问题是在构建操作完成后将装入该卷。 That is why this approach won't work for you.
这就是为什么这种方法对您不起作用的原因。
What you will need to do is copy those resources inside container in a dockerfile
. 您需要做的是将这些资源复制到
dockerfile
容器内。
Assuming you don't have a dockerfile defined. 假设您没有定义dockerfile。 You can create your on making
nginx
your base image. 您可以创建使
nginx
成为基本图像的对象。
Which would look somewhat like.... 看起来有点像...
From nginx:latest
COPY from/host/dir to/container/container/dir
Something similar but in different context they are explaining here 相似但在不同上下文中的他们在这里解释
Cheers! 干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.