语境
我有一个Dockerfile来创建包含apache have服务器的映像。但是,我也希望使用Dockerfile构建我的网站,这样构建过程就不会依赖于开发人员的本地环境。请注意,码头容器只用于本地开发,而不是用于生产。
问题所在
我有一个Dockerfile:
FROM httpd
RUN apt-get update -yq
RUN apt-get -yq install curl gnupg
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash
RUN apt-get update -yq
RUN apt-get install -yq \
dh-autoreconf=19 \
ruby=1:2.5.* \
ruby-dev=1:2.5.* \
nodejs
我建造它:
sudo docker build --no-cache .
构建成功完成,下面是输出的一部分:
Step 9/15 : RUN curl -sL https://deb.nodesource.com/setup_12.x | bash
---> Running in e6c747221ac0
......
......
......
Removing intermediate container 5a07dd0b1e01
---> 6279003c1e80
Successfully built 6279003c1e80
但是,当我使用以下方法在容器中运行映像时:
sudo docker container run --rm -it --name=debug 6279003c1e80 /bin/bash
然后,在容器中执行apt-cache policy
时,它不会显示本应使用curl命令添加的存储库。同时,在执行apt-cache policy nodejs
时,它显示已经安装了旧版本。
但是,当我在容器中运行以下代码时:
curl -sL https://deb.nodesource.com/setup_12.x | bash
apt-cache policy
apt-cache policy nodejs
它向我展示了存储库的添加,并显示了新的nodejs版本是可用的。
那么,为什么在停靠器文件中使用curl命令时,它似乎不起作用,但在容器中从shell手动执行时,它就起作用了吗?我该怎么解决这个问题呢?
更新
sudo docker system prune
和重建图像,但没有成功。RUN apt-get update -yq \
&& apt-get -yq install curl gnupg && \
&& curl -sL https://deb.nodesource.com/setup_12.x | bash \
&& apt-get update -yq \
&& apt-get install -yq \
dh-autoreconf=19 \
ruby=1:2.5.* \
ruby-dev=1:2.5.* \
nodejs \
&& rm -rf /var/lib/apt/lists/*
发布于 2020-06-11 05:28:01
您可能会遇到缓存层的问题。Dockerfile中有关于使用apt的最佳实践文档中的长截面。可能值得一读。
要点是Docker不识别第一个和第二个RUN apt-get update
之间的任何区别,也不知道apt-get install
依赖于一个新的apt-get update
层。
解决方案是将所有这些合并到一个RUN
命令(推荐)中,或者在构建过程(docker build --no-cache
)期间禁用缓存。
RUN apt-get update -yq \
&& apt-get -yq install curl gnupg ca-certificates \
&& curl -L https://deb.nodesource.com/setup_12.x | bash \
&& apt-get update -yq \
&& apt-get install -yq \
dh-autoreconf=19 \
ruby=1:2.5.* \
ruby-dev=1:2.5.* \
nodejs
编辑:在本地运行您的Dockerfile,我注意到curl
命令没有输出。删除-s
标志(失败静默)之后,可以看到由于无法验证服务器的SSL证书而导致它失败:
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
解决该问题的方法是在运行ca-certificates
之前安装curl
。我更新了上面的RUN
命令。
https://stackoverflow.com/questions/62325403
复制相似问题