Docker容器未复制证书。

huangapple go评论73阅读模式
英文:

Docker container not copying certificate

问题

我想使用Docker运行一个HTTPS服务器,但似乎无法将证书复制过去。

我想使用绑定挂载(bind mount),这样每当我更新SSL证书时就不必重新启动服务器。

当我使用下面列出的命令时,Docker无法工作。

在我的Linux机器上,目录/etc/letsencrypt/live/mydomain/下有fullchain.pemprivkey.pem文件。

我的代码如下:

	go func() {
		err := http.ListenAndServeTLS(":443",
			"/etc/letsencrypt/live/mydomain/fullchain.pem",
			"/etc/letsencrypt/live/mydomain/privkey.pem",
			r)
		if err != nil {
			log.Fatal("ListenAndServe: ", err)
		}
	}()

当我运行Docker命令:

docker run -v /etc/letsencrypt/live/mydomain:/etc/letsencrypt/live/mydomain -p 443:443 -p 80:80 imagehere

我得到以下错误:

2022/11/20 12:28:32 ListenAndServe: open /etc/letsencrypt/live/mydomain/fullchain.pem: no such file or directory

我做错了什么?

英文:

I want to run a https server using docker, I cannot seem to get the certificate to copy across

I want to use a bind mount so I don't have to restart the server whenever I renew the ssl certificate

Docker does not work when I use the command I'll list below

In my linux machine there is fullchain.pem and privkey.pem inside:

/etc/letsencrypt/live/mydomain/

My code is as such:


	go func() {
		err := http.ListenAndServeTLS(":443",
			"/etc/letsencrypt/live/mydomain/fullchain.pem",
			"/etc/letsencrypt/live/mydomain/privkey.pem",
			r)
		if err != nil {
			log.Fatal("ListenAndServe: ", err)
		}
	}()

When I run the docker command:

docker run  -v /etc/letsencrypt/live/mydomain:/etc/letsencrypt/live/mydomain -p 443:443 -p 80:80 imagehere

I get this:

2022/11/20 12:28:32 ListenAndServe: open /etc/letsencrypt/live/mydomain/fullchain.pem: no such file or directory

What am I doing wrong?

答案1

得分: 2

我刚刚成功修复了它。

由于写入权限、读取权限等原因,除非我将证书移动到我的主目录,否则它无法正常工作。

所以我只是将证书移动到了~/cert目录,并重复了docker命令,将~/cert绑定到...,然后它就可以工作了。

我认为这是因为certbot为证书使用了0700权限,而不是由于目录的原因。所以docker无法读取这些文件。

英文:

I just managed to fix it

For some reason, due to write permissions, read perms, etc it didn't work unless I moved the certificates to my home directory

So I just moved the certs to ~/cert and repeated the docker command binding ~/cert to ... and it worked.

I believe this is due to certbot using 0700 permissions for certificates, not due to the directory. So docker cannot read the files

huangapple
  • 本文由 发表于 2022年11月20日 20:32:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/74508116.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定