0

I am install requests in a docker container to use it in a python script. Here is my docker file.

# stage1 as builder
FROM node:10-alpine as builder
FROM python:3.7
FROM nginx:alpine

RUN pip install --upgrade pip && \
    pip install requests

WORKDIR /opt/
ADD init.py /opt/
RUN python init.py
## Remove default nginx index page
RUN rm -rf /usr/share/nginx/html/*

WORKDIR /opt/app-ui
# copy the package.json to install dependencies
COPY agentform/dist/agentform/* /usr/share/nginx/html/


EXPOSE 4200 80

ENTRYPOINT ["nginx", "-g", "daemon off;"]

docker-compose build shows the following error.

Step 4/12 : RUN pip install --upgrade pip &&     pip install requests
 ---> Running in e7ad71640bb3
/bin/sh: pip: not found
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install --upgrade pip &&     pip install requests' returned a non-zero code: 127
Vinay Joseph
  • 5,515
  • 10
  • 54
  • 94

1 Answers1

1

According to the docs:

With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image. To show how this works, let’s adapt the Dockerfile from the previous section to use multi-stage builds. https://docs.docker.com/develop/develop-images/multistage-build/

so, pip is not present in the final image, since you are getting FROM nginx:alpine after get python

I think the best solution is to pip install before last FROM, and keep as suggested here: https://pythonspeed.com/articles/multi-stage-docker-python/

Tiago Gomes
  • 357
  • 4
  • 12