docker-library / python

Docker Official Image packaging for Python
https://www.python.org/
MIT License
2.5k stars 1.04k forks source link

git not found in python:3.6-slim (breaks CI/CD pipelines) #391

Closed jennirinker closed 5 years ago

jennirinker commented 5 years ago

My CI/CD pipelines broke after the most recent GitLab server updates, and it seems to be related to the use of CMD versus ENTRYPOINT in docker files. My CI with Anaconda3 images broke (no pip) and my CI with Python3 images are also broken (no git). GitHub user leycec explains the issue better in this issue over here.

Suggested fix: if it makes sense, switch the CMD command in the dockerfile to ENTRYPOINT so that it's mandatorily run on entry.

Here is an example failed pipeline:

Running with gitlab-runner 10.0.2 (a9a76a50)
  on synnefo-docker-iamge (761634a5)
Using Docker executor with image python:3.6-slim ...
Using docker image sha256:f15c08281654e1d0c53d0952c0226d08e175f97c6232e8c5d585781e8e23de8b for predefined container...
Pulling docker image python:3.6-slim ...
Using docker image python:3.6-slim ID=sha256:5d4dd7f71a65861c8194384a1ec27503ddc497aaebeb695aff134a28a18d37eb for build container...
Running on runner-761634a5-project-570-concurrent-0 via snf-713...
Fetching changes...
HEAD is now at 4c5d757 trying pip
From https://gitlab.windenergy.dtu.dk/rink/pyconturb
   4c5d757..b1ed2e2  update_docs -> origin/update_docs
Checking out b1ed2e26 as update_docs...
Skipping Git submodules setup
$ pip list
Package    Version
---------- -------
pip        19.0.3 
setuptools 40.8.0 
wheel      0.33.1 
$ pip install -r dev_reqs.txt
Collecting git+https://github.com/vidartf/nbsphinx-link.git (from -r dev_reqs.txt (line 5))
  Cloning https://github.com/vidartf/nbsphinx-link.git to /tmp/pip-req-build-gmc0d7kf
  Error [Errno 2] No such file or directory: 'git': 'git' while executing command git clone -q https://github.com/vidartf/nbsphinx-link.git /tmp/pip-req-build-gmc0d7kf
Cannot find command 'git' - do you have 'git' installed and in your PATH?
ERROR: Job failed: exit code 1
wglambert commented 5 years ago

We don't maintain or interact with the Anaconda3 image, if it's missing pip then you could try making a Dockerfile FROM continuumio/anaconda3 and then include our pip install section https://github.com/docker-library/python/blob/67e7d70195c46f16116a57307c364167cb1302f6/3.6/stretch/slim/Dockerfile#L103-L131

Our slim and alpine variants don't include git as it's 71MB, which is over half the size of the slim image. However the standard python image does include git but is quite large at 922MB

Adding git to the image is also a simple process

$ docker build -t python:3.6-slim-git - << EOF
> FROM python:3.6-slim
> RUN apt-get update \
> && apt-get install -y --no-install-recommends git \
> && apt-get purge -y --auto-remove \
> && rm -rf /var/lib/apt/lists/*
> EOF                                                                                                                                                         
Sending build context to Docker daemon  2.048kB                                                                                                               
Step 1/2 : FROM python:3.6-slim                                                                                                                               
 ---> 5d4dd7f71a65                                                                                                                                            
Step 2/2 : RUN apt-get update && apt-get install -y --no-install-recommends git && apt-get purge -y --auto-remove && rm -rf /var/lib/apt/lists/*              
 ---> Using cache                                                                                                                                             
 ---> cd01b3f89122
Successfully built cd01b3f89122
Successfully tagged python:3.6-slim-git

$ docker images | grep 3.6-slim
python                        3.6-slim-git           cd01b3f89122        About a minute ago   209MB
python                        3.6-slim               5d4dd7f71a65        2 weeks ago          138MB