Billy Darwin
Billy Darwin

Reputation: 525

apt-get not found in Docker

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 ?

Upvotes: 5

Views: 47793

Answers (4)

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

Upvotes: 5

Michael Currin
Michael Currin

Reputation: 680

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.

Upvotes: 0

Mohamed Salah
Mohamed Salah

Reputation: 328

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

Upvotes: 3

shaped
shaped

Reputation: 333

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"]

Upvotes: 11

Related Questions