Openssl命令在Dockerfile Run中不起作用

问题描述 投票:0回答:1

我是Docker的新手。我正在尝试通过一些基本操作来加深我的理解。我有一个非常基本的Web应用程序,我已经创建了该应用程序,并想为其创建一个Dockerfile。我想做的一件事是让Web应用程序通过https交付。我想使用“让我们加密”。当我刚开始时,我在Let's Encrypt的网站上找到了instructions,用于为本地开发创建证书。

我想将其作为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机器上运行Windows的Docker,所以我想也许是由于Windows和Linux之间的行尾不同而出现错误。我确保Dockerfile上的所有行结尾均为LF,而不是CRLF,并且仍然遇到相同的错误。 Dockerfile是UTF-8编码,据我所知也是Linux的标准。

我不知道为什么收到此错误。我需要对命令或dockerfile进行哪些更改才能使上述命令作为Dockerfile构建的一部分正常运行?

docker dockerfile
1个回答
0
投票

由于@ 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")
© www.soinside.com 2019 - 2024. All rights reserved.