skip to Main Content

I have a python script that uses DigitalOcean tools (doctl and kubectl) I want to containerize. This means my container will need python, doctl, and kubectl installed. The trouble is, I figure out how to install both python and DigitalOcean tools in the dockerfile.

I can install python using the base image "python:3" and I can also install the DigitalOcean tools using the base image "alpine/doctl". However, the rule is you can only use one base image in a dockerfile.

So I can include the python base image and install the DigitalOcean tools another way:

FROM python:3
RUN <somehow install doctl and kubectl>
RUN pip install firebase-admin
COPY script.py
CMD ["python", "script.py"]

Or I can include the alpine/doctl base image and install python3 another way.

FROM alpine/doctl
RUN <somehow install python>
RUN pip install firebase-admin
COPY script.py
CMD ["python", "script.py"]

Unfortunately, I’m not sure how I would do this. Any help in how I can get all these tools installed would be great!

3

Answers


  1. just add this with any other thing you want to apt-get install:

    RUN apt-get update && apt-get install -y 
        python3.6 &&
        python3-pip &&
    

    in alpine it should be something like:

    RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python &&
        python3 -m ensurepip &&
        pip3 install --no-cache --upgrade pip setuptools &&
    
    Login or Signup to reply.
  2. This Dockerfile worked for me:

    FROM alpine/doctl
    ENV PYTHONUNBUFFERED=1
    RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
    RUN python3 -m ensurepip
    RUN pip3 install --no-cache --upgrade pip setuptools
    

    This answer comes from here:(https://stackoverflow.com/a/62555259/7479816; I don’t have enough street cred to comment)

    Login or Signup to reply.
  3. You can try multi-stage build as shown below.

    Also check your copy statement, you need to define where you want script.py file to be copied as second parameter. "." will copy it to root directory

    FROM alpine/doctl
    FROM python:3.6-slim-buster
    ENV PYTHONUNBUFFERED 1
    RUN pip install firebase-admin
    COPY script.py .
    CMD ["python", "script.py"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search