Repository: jina-ai/serve
Pull request: fix: disabled pip cache in docker
Describe the bug
All of our hub docker containers contain pip cache which increases its size. This cache is useless.

Describe how you solve it
Add these to our jina dockerfiles. This will lead to smaller jina and hub images especially those with big dependencies like tensorflow and torch. This way we don't need to use flag `--no-cache-dir` in pip installs everywhere.
I also suggest disabling pip version check.

```
ENV PIP_NO_CACHE_DIR=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
```

resolved #1167 

Problem statement:
fix: disable pip cache in docker
**Describe the bug**
All of our docker containers contain pip cache which increases its size. This cache is useless.

**Describe how you solve it**
Add these to our jina debianx dockerfile. This will lead to smaller jina and hub images especially those with big dependencies like tensorflow and torch. This way we don't need to use flag `--no-cache-dir` in pip installs everywhere.
I also suggest disabling pip version check. 
```
ENV PIP_NO_CACHE_DIR=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
```

Hints from issue discussion:

Commit message: fix: disabled pip cache in docker

Patch to review:
diff --git a/Dockerfiles/alpinex.Dockerfile b/Dockerfiles/alpinex.Dockerfile
index 5fc49ca5528ba..84e5369ce7847 100644
--- a/Dockerfiles/alpinex.Dockerfile
+++ b/Dockerfiles/alpinex.Dockerfile
@@ -23,11 +23,13 @@ ADD cli ./cli/
 ADD jina ./jina/
 
 ENV PYTHONPATH=$PYTHONPATH:/usr/lib/python3.8/dist-packages:/usr/local/lib/python3.8/site-packages:/usr/lib/python3/dist-packages:/usr/local/lib/python3/site-packages
+ENV PIP_NO_CACHE_DIR=1
+ENV PIP_DISABLE_PIP_VERSION_CHECK=1
 
 # py3-scipy
 RUN apk add --no-cache py3-pyzmq py3-numpy grpc && \
     ln -s locale.h /usr/include/xlocale.h && \
-    pip install . --no-cache-dir --compile && \
+    pip install . --compile && \
     find /usr/lib/python3.8/ -name 'tests' -exec rm -r '{}' + && \
     find /usr/lib/python3.8/site-packages/ -name '*.so' -print -exec sh -c 'file "{}" | grep -q "not stripped" && strip -s "{}"' \; && \
     rm /usr/include/xlocale.h && \
diff --git a/Dockerfiles/debianx.Dockerfile b/Dockerfiles/debianx.Dockerfile
index bcfaa5c696120..487abd46053c7 100644
--- a/Dockerfiles/debianx.Dockerfile
+++ b/Dockerfiles/debianx.Dockerfile
@@ -29,6 +29,8 @@ ENV PYTHONPATH=$PYTHONPATH:/usr/lib/python3.7/dist-packages:/usr/local/lib/pytho
 ENV JINA_VERSION=$JINA_VERSION
 ENV JINA_VCS_VERSION=$VCS_REF
 ENV JINA_BUILD_DATE=$BUILD_DATE
+ENV PIP_NO_CACHE_DIR=1
+ENV PIP_DISABLE_PIP_VERSION_CHECK=1
 
 WORKDIR /jina/
 
@@ -37,8 +39,8 @@ ADD cli ./cli/
 ADD jina ./jina/
 
 RUN ln -s locale.h /usr/include/xlocale.h && \
-    pip install . --no-cache-dir --compile && \
-    if [ -n "$INSTALL_DEV" ]; then pip install .[devel] --no-cache-dir --compile; fi && \
+    pip install . --compile && \
+    if [ -n "$INSTALL_DEV" ]; then pip install .[devel] --compile; fi && \
     rm -rf /tmp/* && rm -rf /jina && \
     rm /usr/include/xlocale.h
 


Code review comments:
diff_hunk: @@ -23,11 +23,13 @@ ADD cli ./cli/
 ADD jina ./jina/
 
 ENV PYTHONPATH=$PYTHONPATH:/usr/lib/python3.8/dist-packages:/usr/local/lib/python3.8/site-packages:/usr/lib/python3/dist-packages:/usr/local/lib/python3/site-packages
+ENV PIP_NO_CACHE_DIR=1
path: Dockerfiles/alpinex.Dockerfile
text: @user1:
Isnt it possible to put all these in the same layer?