Dockerfile在本地工作正常,但在.gitlab-ci.yml中不工作

Dockerfile在本地工作正常,但在.gitlab-ci.yml中不工作,docker,dockerfile,gitlab-ci,Docker,Dockerfile,Gitlab Ci,我有一个Dockerfile,以 FROM python:3.7-slim RUN mkdir -p /usr/share/man/man1mkdir -p /usr/share/man/man1 RUN apt-get update && apt-get install -y openjdk-8-jdk 在本地,这种方法非常有效。因此,我编写了.gitlab-ci.yml文件,如下所示: docker-image: stage: containerise_require

我有一个Dockerfile,以

FROM python:3.7-slim

RUN mkdir -p /usr/share/man/man1mkdir -p /usr/share/man/man1
RUN apt-get update && apt-get install -y openjdk-8-jdk
在本地,这种方法非常有效。因此,我编写了.gitlab-ci.yml文件,如下所示:

docker-image:
  stage: containerise_requirements
  image: docker:19.03.1
  tag:
    - my-runner
  services:
    - docker:19.03.1-dind
  variables:
    DOCKER_TLS_CERTDIR: ""
  script:
    - docker pull $IMAGENAME:latest || true
    - docker build --cache-from $IMAGENAME:latest --tag $IMAGENAME:$CI_COMMIT_SHA --tag $IMAGENAME:latest .
    - docker push $IMAGENAME:$CI_COMMIT_SHA
    - docker push $IMAGENAME:latest
但是现在,我得到了错误

Sending build context to Docker daemon  1.031MB

Step 1/7 : FROM python:3.7-slim
 ---> b5a7c089ece3
Step 2/7 : RUN mkdir -p /usr/share/man/man1mkdir -p /usr/share/man/man1
 ---> Running in 0d90afc1839b
Removing intermediate container 0d90afc1839b
 ---> b8c22c4288c7
Step 3/7 : RUN apt-get update && apt-get install -y openjdk-8-jdk
 ---> Running in 1052a5ffb708
Get:1 http://security.debian.org/debian-security buster/updates InRelease [39.1 kB]
Get:2 http://deb.debian.org/debian buster InRelease [122 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [49.3 kB]
Get:4 http://security.debian.org/debian-security buster/updates/main amd64 Packages [98.2 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 Packages [7899 kB]
Get:6 http://deb.debian.org/debian buster-updates/main amd64 Packages [5792 B]
Fetched 8212 kB in 2s (4828 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package openjdk-8-jdk

这让我感到惊讶——如果Dockerfile在本地构建,为什么不在CI期间构建呢?

Python:3.7-slim现在基于Debian 10。openjdk-8-jdk中没有这样的包。因此,要么安装openjdk-11-jdk,要么添加sid Repo源代码。最有可能的是,您的本地Python映像较旧,因此基于较旧的Debian(例如Stretch)。

但是,当我在本地运行
docker build-t my tag时,它为什么会工作。
?谢谢-可以确认更改为
Python:3.7-Stretch
允许一切恢复到以前的工作状态。也许这是使用哈希而不是标签的一个教训?很高兴它成功了:)当使用第三方图像时,你必须认真阅读文档(希望它是好的和正确的)。Docker Hub上的Python图像文档说明了您所经历的事实。但别担心,这种事情在docker身上经常发生;正如你所说的。。。经验:)