0

If I add

FROM nginx:1.16-alpine

to my Dockerfile, my build breaks with the error:

/bin/sh: pip: not found

I tried sending an update command via :

RUN set -xe \
    && apt-get update \
    && apt-get install python-pip

but then I get the error that apt-get can't be found.

Here is my Dockerfile:

FROM python:3.7.2-alpine
FROM nginx:1.16-alpine

ENV INSTALL_PATH /web

RUN mkdir -p $INSTALL_PATH

WORKDIR $INSTALL_PATH

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .

CMD gunicorn -b 0.0.0.0:9000 --access-logfile - "web.webhook_server:create_app()"

If I remove that one line:

FROM nginx:1.16-alpine

it all runs fine. But of course, I need nginx.

What could be going wrong here? I'm very confused.

robster
  • 626
  • 1
  • 7
  • 22
  • Possible duplicate of [Docker: Combine multiple images](https://stackoverflow.com/questions/27214757/docker-combine-multiple-images) – David Maze May 03 '19 at 10:17

2 Answers2

1

As mentioned in this issue:

Using multiple FROM is not really a feature but a bug [...]

Note that :
- There is discussion to remove support for multiple FROM : #13026

So you should decide for one image that fits you most and then intall the necessary packages you need via RUN apk add. Note that both images you used as base are based themself on alpine linux and you need to use apk instead of apt-get to install packages.

Marcus Held
  • 635
  • 4
  • 15
  • Thanks for this. That does make sense (I'm quite new at docker / compose in general). I just swapped them over to test, I commented out the `FROM python:3.7.2-alpine` and left the `FROM nginx:1.16-alpine` and I get the same error. If I do it the other way around though it works. So it seems the list `FROM nginx:1.16-alpine` is the issue? – robster May 03 '19 at 04:27
  • 1
    You mean you get the same error that `apt-get` was not found? Thats due to the reason that you need to use `apk` instead. So exchange the `RUN apt-get ...` block with: `RUN apk add --update py-pip` – Marcus Held May 03 '19 at 04:33
  • OK my bad, I didn't follow your full comment (or know what it meant fully). Some research later and I've added `run apk update` and `run apk add py-pip` to the Dockerfile and it's working. Thank you for your help. Much appreciated. – robster May 03 '19 at 04:33
0

Use "FROM nginx:1.16" instead of "FROM nginx:1.16-alpine". The alpine image doesn't have apt. With "nginx:1.16" you can install your extra packages with apt.

The FROM directive tells the docker daemon to extend from an image. You cannot extend from 2 different images.

Let me know if this helps.

Mihai
  • 9,526
  • 2
  • 18
  • 40