当我使用以下 Dockerfile :
在本地计算机上运行docker时FROM python:3
WORKDIR /app
COPY . /app
RUN apt-get update && apt-get install -y libhunspell-1.3-0
RUN pip install -r requirements.txt
EXPOSE 9876
CMD ["python","flask_compose.py"]
来自以下存储库 jessie 的 libhunspell :
Get:1 http://security.debian.org jessie/updates InRelease [94.4 kB]
Ign http://deb.debian.org jessie InRelease
Get:2 http://deb.debian.org jessie-updates InRelease [145 kB]
Get:3 http://security.debian.org jessie/updates/main amd64 Packages [623 kB]
Get:4 http://deb.debian.org jessie Release.gpg [2434 B]
Get:5 http://deb.debian.org jessie Release [148 kB]
Get:6 http://deb.debian.org jessie-updates/main amd64 Packages [23.0 kB]
Get:7 http://deb.debian.org jessie/main amd64 Packages [9064 kB]
一切都很好(图像构建并成功运行)。
不幸的是,当我使用相同的 Dockerfile 在gitlab资源库上运行docker时,它从另一个存储库调用update apt-get( stretch ):
Ign:1 http://deb.debian.org/debian stretch InRelease
Get:2 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
Get:3 http://deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:4 http://deb.debian.org/debian stretch Release [118 kB]
Get:5 http://deb.debian.org/debian stretch Release.gpg [2434 B]
Get:6 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [440 kB]
Get:7 http://deb.debian.org/debian stretch-updates/main amd64 Packages [12.1 kB]
Get:8 http://deb.debian.org/debian stretch/main amd64 Packages [9530 kB]
由于这种不一致,gitlab CI / CD会抛出以下异常:
E: Unable to locate package libhunspell-1.3-0
E: Couldn't find any package by glob 'libhunspell-1.3-0'
E: Couldn't find any package by regex 'libhunspell-1.3-0'
The command '/bin/sh -c apt-get install -y libhunspell-1.3-0' returned a non-zero code: 100
ERROR: Job failed: exit code 100
有谁知道如何更改我的 Dockerfile 本地和gitlab使用相同的软件包存储库?
答案 0 :(得分:3)
python的当前标记:3点指向基于Debian stretch的图像。要更新您的本地环境,请运行docker pull python:3
或使用--pull
选项运行您的构建。
您还可以选择更具体的标记来强制使用python所需的基本图像。有关python的信息,请参阅docker hub页面以查看所有可能的标记,例如python:3-jessie
。
答案 1 :(得分:0)
从gitlab official forum我找到了解决问题的解决方案。
1)定义setup.sh
文件并执行以下命令:
echo "deb http://pkg.adfinis-sygroup.ch/debian/ jessie main non-free contrib" > /etc/apt/sources.list
echo "deb http://security.debian.org/ jessie/updates main" >> /etc/apt/sources.list
echo "deb http://pkg.adfinis-sygroup.ch/debian/ jessie-updates main contrib non-free" >> /etc/apt/sources.list
apt-get update
apt-get install --no-install-recommends -y libhunspell-1.3-0
2)在Dockerfile
中添加以下命令:
From python:3
ADD setup.sh /opt/
RUN /bin/bash /opt/setup.sh
PS :虽然我的黑客行为非常好,但我更喜欢@BMitch解决方案。
通过扩展@Bmitch解决方案,我将图像大小从约600减少到~150 Dockerfile
:
FROM python:3-slim-jessie
WORKDIR .
# hunspell deps
RUN apt-get update && apt-get install --no-install-recommends -y libtool libc6-dev gcc g++ build-essential libhunspell-1.3-0
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["python","flask_compose.py"]