2

I've got this Dockerfile:

FROM python:3.6-alpine
FROM ubuntu
FROM alpine

RUN apk update && \
    apk add --virtual build-deps gcc python-dev musl-dev
RUN apt-get update && apt-get install -y python-pip

WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python", "main.py"]

and it's throwing error saying /bin/sh: apt-get: not found. I thought apt-get package is part of Ubuntu image that I'm pulling on the second line but yet it's giving me this error.

How can I fix this ?

Billy Darwin
  • 465
  • 2
  • 6
  • 11

4 Answers4

9

as tkausl said: you can only use one base image (one FROM).

alpine's package manager is apk not apt-get. you have to use apk to install packages. however, pip is already available.

that Dockerfile should work:

FROM python:3.6-alpine

RUN apk update && \
    apk add --virtual build-deps gcc python-dev musl-dev

WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python", "main.py"]
shaped
  • 306
  • 2
  • 4
  • One question where should I keep the requirement.txt file. can you tell me that? Because when I keep the requirement.txt file in the same place where docker file is there it displays ' no such file or directory' – Pradap Pandian Feb 16 '20 at 05:04
  • 1
    You have to copy the requirements.txt into the container before running the pip install... – shaped Feb 18 '20 at 16:45
5

apt-get does not work because the active Linux distribution is alpine, and it does not have the apt-get command.

You can fix it using apk command. enter image description here

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
1

most probbly the image you're using is Alpine, so you can't use apt-get you can use Ubuntu's package manager.

you can use apk update and apk add

Mohamed Salah
  • 160
  • 1
  • 5
0

Multiple FROM lines can be used in a single Dockerfile.

See discussion and Multi stage tutorial

The use of Python Alpine, plus Ubuntu, plus Ubuntu is probably redundant. The Python Alpine one should be sufficient as it uses Alpine internally.

I had a similar issue not with apk but with apt-get.

FROM node:14

FROM jekyll/jekyll

RUN apt-get update
RUN apt-get install -y \
  sqlite

Error:

/bin/sh: apt-get: not found

If I change the order, then it works.

FROM node:14

RUN apt-get update
RUN apt-get install -y \
  sqlite

FROM jekyll/jekyll

Note, as in first link I added above, multiple FROMs might removed from Docker as a feature.

Michael Currin
  • 615
  • 5
  • 14