如何在 dockerfile 中的 cd 命令后执行 .sh 文件?
How can I execute a .sh file after cd command in a dockerfile?
我正在尝试在 python 基础 docker 映像中安装 Libressl。 Python 图像默认有 openssl。
我的Dockerfile
代码:
FROM python:3.7
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install git cpp make dh-autoreconf -y
RUN pip3 install requests
RUN git clone https://github.com/libressl-portable/portable.git /portable
RUN cd /portable \
./autogen.sh \
./configure --prefix=/opt/libressl --enable-nc \
make check \
make install
RUN echo "alias openssl='/opt/libressl/bin/openssl'" >> ~/.bashrc
COPY . /app
WORKDIR /app
CMD ["python3", "./debug.py"]
但是,我发现git克隆的很好,但是下一个命令失败了。
连autogen.sh
好像都没有执行。
我如何找到那个 .bashrc
文件?
当我使用source ~/.bashrc
时,找不到源命令,因为命令是运行和/bin/sh
。
我的 Dockerfile
可能有什么问题?
谢谢:)
要组合多个命令调用,请使用运算符 &&
。此外,您可以对两个目标使用一个 make call
cd /portable && \
./autogen.sh && \
./configure --prefix=/opt/libressl --enable-nc && \
make check install
@alexander 的回答很棒。
另一种方法是:从 Dockerfile 执行 shell 脚本并将所有 shell 命令放在一个地方。使 Dockerfile 更优雅。
例如:
FROM python:3.7
COPY . /app
RUN ./app/script.sh
WORKDIR /app
CMD ["python3", "./debug.py"]
和 script.sh(您编写的是简单的 shell 脚本)(copy\past 您发布的内容未经测试):
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install git cpp make dh-autoreconf -y
pip3 install requests
git clone https://github.com/libressl-portable/portable.git /portable
cd /portable \
./autogen.sh \
./configure --prefix=/opt/libressl --enable-nc \
make check
make install
echo "alias openssl='/opt/libressl/bin/openssl'" >> ~/.bashrc
我正在尝试在 python 基础 docker 映像中安装 Libressl。 Python 图像默认有 openssl。
我的Dockerfile
代码:
FROM python:3.7
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install git cpp make dh-autoreconf -y
RUN pip3 install requests
RUN git clone https://github.com/libressl-portable/portable.git /portable
RUN cd /portable \
./autogen.sh \
./configure --prefix=/opt/libressl --enable-nc \
make check \
make install
RUN echo "alias openssl='/opt/libressl/bin/openssl'" >> ~/.bashrc
COPY . /app
WORKDIR /app
CMD ["python3", "./debug.py"]
但是,我发现git克隆的很好,但是下一个命令失败了。
连autogen.sh
好像都没有执行。
我如何找到那个 .bashrc
文件?
当我使用source ~/.bashrc
时,找不到源命令,因为命令是运行和/bin/sh
。
我的 Dockerfile
可能有什么问题?
谢谢:)
要组合多个命令调用,请使用运算符 &&
。此外,您可以对两个目标使用一个 make call
cd /portable && \
./autogen.sh && \
./configure --prefix=/opt/libressl --enable-nc && \
make check install
@alexander 的回答很棒。 另一种方法是:从 Dockerfile 执行 shell 脚本并将所有 shell 命令放在一个地方。使 Dockerfile 更优雅。
例如:
FROM python:3.7
COPY . /app
RUN ./app/script.sh
WORKDIR /app
CMD ["python3", "./debug.py"]
和 script.sh(您编写的是简单的 shell 脚本)(copy\past 您发布的内容未经测试):
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install git cpp make dh-autoreconf -y
pip3 install requests
git clone https://github.com/libressl-portable/portable.git /portable
cd /portable \
./autogen.sh \
./configure --prefix=/opt/libressl --enable-nc \
make check
make install
echo "alias openssl='/opt/libressl/bin/openssl'" >> ~/.bashrc