docker 由于 alpine 错误无法构建
docker can't build because of alpine error
您好,我正在尝试构建一个 docker 和 Docker 文件,如下所示。
FROM alpine
LABEL description "Nginx + uWSGI + Flask based on Alpine Linux and managed by Supervisord"
# Copy python requirements file
COPY requirements.txt /tmp/requirements.txt
RUN apk add --no-cache \
python3 \
bash \
nginx \
uwsgi \
uwsgi-python3 \
supervisor && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --upgrade pip setuptools && \
pip3 install -r /tmp/requirements.txt && \
rm /etc/nginx/conf.d/default.conf && \
rm -r /root/.cache
# Copy the Nginx global conf
COPY nginx.conf /etc/nginx/
# Copy the Flask Nginx site conf
COPY flask-site-nginx.conf /etc/nginx/conf.d/
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number
COPY uwsgi.ini /etc/uwsgi/
# Custom Supervisord config
COPY supervisord.conf /etc/supervisord.conf
# Add demo app
COPY ./app /app
WORKDIR /app
CMD ["/usr/bin/supervisord"]
错误看起来像
Sending build context to Docker daemon 250.9kB
Step 1/11 : FROM alpine
---> 196d12cf6ab1
Step 2/11 : LABEL description "Nginx + uWSGI + Flask based on Alpine Linux and managed by Supervisord"
---> Using cache
---> d8d38c761b8d
Step 3/11 : COPY requirements.txt /tmp/requirements.txt
---> Using cache
---> cb29eb34ca46
Step 4/11 : RUN apk add --no-cache python3 bash nginx uwsgi uwsgi-python3 supervisor && python3 -m ensurepip && rm -r /usr/lib/python*/ensurepip && pip3 install --upgrade pip setuptools && pip3 install -r /tmp/requirements.txt && rm /etc/nginx/conf.d/default.conf && rm -r /root/.cache
---> Running in 3d568d2620dd
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
ERROR: unsatisfiable constraints:
bash (missing):
required by: world[bash]
nginx (missing):
required by: world[nginx]
python3 (missing):
required by: world[python3]
supervisor (missing):
required by: world[supervisor]
uwsgi (missing):
required by: world[uwsgi]
uwsgi-python3 (missing):
required by: world[uwsgi-python3]
The command '/bin/sh -c apk add --no-cache python3 bash nginx uwsgi uwsgi-python3 supervisor && python3 -m ensurepip && rm -r /usr/lib/python*/ensurepip && pip3 install --upgrade pip setuptools && pip3 install -r /tmp/requirements.txt && rm /etc/nginx/conf.d/default.conf && rm -r /root/.cache' returned a non-zero code: 6
一个月前它还不错。由于 Docker 中的知识有限,我无法弄清楚是什么导致了错误。快速 google 搜索找到了这两个链接:link1 link2 但是其中 none 有效。
行:
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
基本上是说您要么离线,要么 alpinelinux 存储库已关闭。我在互联网上找不到任何相关信息,但过去发生过几次。或者它可能是你和 cdn 之间某处的网络问题。
您可以随时从 http://dl-cdn.alpinelinux.org/alpine/MIRRORS.txt 中选择自己的镜像并像这样设置它:
RUN echo http://repository.fit.cvut.cz/mirrors/alpine/v3.8/main > /etc/apk/repositories; \
echo http://repository.fit.cvut.cz/mirrors/alpine/v3.8/community >> /etc/apk/repositories
(根据你的版本修改v3.8
)
另外正如@emix 所指出的,你不应该为你的基本图像使用 :latest
标签。使用例如 3.8
,或具有您需要的软件包版本的版本。
使用标志“--network host”构建 docker 解决了这个问题。这里是 link.
如果您能够手动下载文件,请尝试重新启动您的 docker 服务。它对我有用..
为标题提供更通用的故障排除答案。在另一个容器中测试您的 docker 命令。这可能是另一个您不介意破坏的 运行ning 容器,或者最好是一个基本容器(在本例中为 alpine),您可以在其中 运行 shell 上的 Dockerfile 命令。可能不是原始问题中网络问题的解决方案,但在其他情况下很好。
apk 错误消息并不总是最有用的。看看下面的例子:
/ # apk add --no-cache influxdb-client
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
influxdb-client (missing):
required by: world[influxdb-client]
/ #
/ #
/ #
/ #
/ # apk add --no-cache influxdb
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/1) Installing influxdb (1.8.0-r1)
Executing influxdb-1.8.0-r1.pre-install
Executing busybox-1.31.1-r19.trigger
OK: 613 MiB in 98 packages
顺便说一下,https://pkgs.alpinelinux.org/packages 是查找 Alpine 包名称的好地方,这将修复上面的示例。
另一个修复 -
我将 8.8.8.8
添加到我的 /etc/resolv.conf
并重新启动了 docker 守护程序。它为我解决了这个问题。
由于网络问题,经常会出现这种错误。
尝试使用 https 镜像而不是 http。
RUN sed -i -e 's/http:/https:/' /etc/apk/repositories
我想我已经完成了此处建议的所有操作,但没有成功。
- 将 http 更改为 https
- 使用
--network host
技巧
- 在resolv.conf
中添加8.8.8.8
- 使用镜像
我可以毫无问题地在那台机器上下载索引。
但是当使用 Docker(有或没有 gitlab-runner)时,它就失败了。
它在同一网络上具有相同架构的另一台机器上运行良好 (armv7
)。
如果我的第一条指令是
RUN wget https://mirrors.ircam.fr/pub/alpine/v3.15/main/armv7/APKINDEX.tar.gz
我得到 ---> Running in 19a0630d633a wget: bad address 'mirrors.ircam.fr'
-在Ubuntu
对我来说这是一个 DNS 错误。通过设置 /etc/docker/daemon.json 和
{
"dns": ["8.8.8.8"]
}
然后用
重新启动 docker
sudo service docker restart
我又能构建图像了。
https://github.com/gliderlabs/docker-alpine/issues/334#issuecomment-450598069
-在Windows
C:/Users/Administrator(or any other Username)/.docker/daemon.json
并添加
{
...,
"dns": ["8.8.8.8"]
}
尝试重新启动 docker 服务,它对我和其他人有效:
sudo systemctl restart docker docker.service
感谢:https://github.com/gliderlabs/docker-alpine/issues/334#issuecomment-408826204
您好,我正在尝试构建一个 docker 和 Docker 文件,如下所示。
FROM alpine
LABEL description "Nginx + uWSGI + Flask based on Alpine Linux and managed by Supervisord"
# Copy python requirements file
COPY requirements.txt /tmp/requirements.txt
RUN apk add --no-cache \
python3 \
bash \
nginx \
uwsgi \
uwsgi-python3 \
supervisor && \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --upgrade pip setuptools && \
pip3 install -r /tmp/requirements.txt && \
rm /etc/nginx/conf.d/default.conf && \
rm -r /root/.cache
# Copy the Nginx global conf
COPY nginx.conf /etc/nginx/
# Copy the Flask Nginx site conf
COPY flask-site-nginx.conf /etc/nginx/conf.d/
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number
COPY uwsgi.ini /etc/uwsgi/
# Custom Supervisord config
COPY supervisord.conf /etc/supervisord.conf
# Add demo app
COPY ./app /app
WORKDIR /app
CMD ["/usr/bin/supervisord"]
错误看起来像
Sending build context to Docker daemon 250.9kB
Step 1/11 : FROM alpine
---> 196d12cf6ab1
Step 2/11 : LABEL description "Nginx + uWSGI + Flask based on Alpine Linux and managed by Supervisord"
---> Using cache
---> d8d38c761b8d
Step 3/11 : COPY requirements.txt /tmp/requirements.txt
---> Using cache
---> cb29eb34ca46
Step 4/11 : RUN apk add --no-cache python3 bash nginx uwsgi uwsgi-python3 supervisor && python3 -m ensurepip && rm -r /usr/lib/python*/ensurepip && pip3 install --upgrade pip setuptools && pip3 install -r /tmp/requirements.txt && rm /etc/nginx/conf.d/default.conf && rm -r /root/.cache
---> Running in 3d568d2620dd
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
ERROR: unsatisfiable constraints:
bash (missing):
required by: world[bash]
nginx (missing):
required by: world[nginx]
python3 (missing):
required by: world[python3]
supervisor (missing):
required by: world[supervisor]
uwsgi (missing):
required by: world[uwsgi]
uwsgi-python3 (missing):
required by: world[uwsgi-python3]
The command '/bin/sh -c apk add --no-cache python3 bash nginx uwsgi uwsgi-python3 supervisor && python3 -m ensurepip && rm -r /usr/lib/python*/ensurepip && pip3 install --upgrade pip setuptools && pip3 install -r /tmp/requirements.txt && rm /etc/nginx/conf.d/default.conf && rm -r /root/.cache' returned a non-zero code: 6
一个月前它还不错。由于 Docker 中的知识有限,我无法弄清楚是什么导致了错误。快速 google 搜索找到了这两个链接:link1 link2 但是其中 none 有效。
行:
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
基本上是说您要么离线,要么 alpinelinux 存储库已关闭。我在互联网上找不到任何相关信息,但过去发生过几次。或者它可能是你和 cdn 之间某处的网络问题。
您可以随时从 http://dl-cdn.alpinelinux.org/alpine/MIRRORS.txt 中选择自己的镜像并像这样设置它:
RUN echo http://repository.fit.cvut.cz/mirrors/alpine/v3.8/main > /etc/apk/repositories; \
echo http://repository.fit.cvut.cz/mirrors/alpine/v3.8/community >> /etc/apk/repositories
(根据你的版本修改v3.8
)
另外正如@emix 所指出的,你不应该为你的基本图像使用 :latest
标签。使用例如 3.8
,或具有您需要的软件包版本的版本。
使用标志“--network host”构建 docker 解决了这个问题。这里是 link.
如果您能够手动下载文件,请尝试重新启动您的 docker 服务。它对我有用..
为标题提供更通用的故障排除答案。在另一个容器中测试您的 docker 命令。这可能是另一个您不介意破坏的 运行ning 容器,或者最好是一个基本容器(在本例中为 alpine),您可以在其中 运行 shell 上的 Dockerfile 命令。可能不是原始问题中网络问题的解决方案,但在其他情况下很好。
apk 错误消息并不总是最有用的。看看下面的例子:
/ # apk add --no-cache influxdb-client
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
influxdb-client (missing):
required by: world[influxdb-client]
/ #
/ #
/ #
/ #
/ # apk add --no-cache influxdb
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/1) Installing influxdb (1.8.0-r1)
Executing influxdb-1.8.0-r1.pre-install
Executing busybox-1.31.1-r19.trigger
OK: 613 MiB in 98 packages
顺便说一下,https://pkgs.alpinelinux.org/packages 是查找 Alpine 包名称的好地方,这将修复上面的示例。
另一个修复 -
我将 8.8.8.8
添加到我的 /etc/resolv.conf
并重新启动了 docker 守护程序。它为我解决了这个问题。
由于网络问题,经常会出现这种错误。
尝试使用 https 镜像而不是 http。
RUN sed -i -e 's/http:/https:/' /etc/apk/repositories
我想我已经完成了此处建议的所有操作,但没有成功。
- 将 http 更改为 https
- 使用
--network host
技巧 - 在resolv.conf 中添加
- 使用镜像
8.8.8.8
我可以毫无问题地在那台机器上下载索引。
但是当使用 Docker(有或没有 gitlab-runner)时,它就失败了。
它在同一网络上具有相同架构的另一台机器上运行良好 (armv7
)。
如果我的第一条指令是
RUN wget https://mirrors.ircam.fr/pub/alpine/v3.15/main/armv7/APKINDEX.tar.gz
我得到 ---> Running in 19a0630d633a wget: bad address 'mirrors.ircam.fr'
-在Ubuntu
对我来说这是一个 DNS 错误。通过设置 /etc/docker/daemon.json 和
{
"dns": ["8.8.8.8"]
}
然后用
重新启动 dockersudo service docker restart
我又能构建图像了。
https://github.com/gliderlabs/docker-alpine/issues/334#issuecomment-450598069
-在Windows
C:/Users/Administrator(or any other Username)/.docker/daemon.json
并添加
{
...,
"dns": ["8.8.8.8"]
}
尝试重新启动 docker 服务,它对我和其他人有效:
sudo systemctl restart docker docker.service
感谢:https://github.com/gliderlabs/docker-alpine/issues/334#issuecomment-408826204