我是 Docker 的新手。我正在尝试通过一些基本操作来增加我的理解。我已经创建了一个非常基本的 web 应用程序,并想为它创建一个 Dockerfile。我想做的一件事是通过 https 交付 webapp。我想使用让我们加密。刚开始时,我在 Let's Encrypt 的网站上找到了为本地开发创建证书的说明。
我想把它作为我的 Dockerfile 的一部分。
我将以下内容添加到我的 Dockerfile 中:
RUN openssl req \
-x509 \
-out localhost.crt \
-keyout localhost.key \
-newkey rsa:2048 \
-nodes \
-sha256 \
-subj "/CN=localhost" \
-extensions EXT \
-config <(printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
每当我docker build
在这个文件上运行命令时,我都会收到以下错误。
Step 12/18 : RUN openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj "/CN=localhost" -extensions EXT -config <(printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
---> Running in 079b3085beba
/bin/sh: 1: Syntax error: "(" unexpected
The command '/bin/sh -c openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj "/CN=localhost" -extensions EXT -config <(printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")' returned a non-zero code: 2
由于我的简单应用程序是 dotnet 应用程序,因此基本映像是FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
. 这是一个构建在3.1.4-buster-slim
debian 容器上的镜像。
然后我运行,docker run -it mcr.microsoft.com/dotnet/core/aspnet:3.1
以便我可以在该根容器上访问 shell,然后我能够将上述命令复制并粘贴到终端中,并且它工作得很好。
我在我的 Windows 机器上运行 Docker for Windows,所以我想可能是由于 Windows 和 Linux 之间的行尾不同而导致错误。我确保 Dockerfile 上的所有行结尾都是LF
和不是,CRLF
并且仍然遇到相同的错误。Dockerfile 是UTF-8
编码,据我所知,它也是 Linux 的标准。
我不知道为什么我会收到这个错误。我需要对命令或 dockerfile 进行哪些更改才能使上述命令作为 Dockerfile 构建的一部分正常工作?
感谢@michaeldel,我能够理解发生了什么问题。
经过一番搜索,我发现在自己的Dockerfile中,可以指定要使用的shell。我将我的 Dockerfile 更新为以下内容,现在一切正常。
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
SHELL ["/bin/bash", "-c"]
RUN echo "$(openssl version)"
RUN openssl req \
-x509 \
-out localhost.crt \
-keyout localhost.key \
-newkey rsa:2048 \
-nodes \
-sha256 \
-subj "/CN=localhost" \
-extensions EXT \
-config <(printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句