Python CLI in Docker



examples/python-3/curl.py
#!/usr/bin/python3

import requests
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('url',                      help='The url to fetch')
parser.add_argument('-I',  action='store_true', help='Show headers only')
args = parser.parse_args()

res = requests.get(args.url)
if args.I:
    for k in res.headers.keys():
        print(f"{k} = {res.headers[k]}")
    exit()

print(res.text)

examples/python-3/Dockerfile
FROM ubuntu:20.04
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y python3

RUN apt-get install -y python3-pip
RUN pip3 install requests
COPY curl.py .
ENTRYPOINT ["python3", "curl.py"]

$ docker build -t mydocker .


docker run --rm mydocker https://httpbin.org/get

This is a simple implementation of a curl-like script in Python. Wrapped in a Docker container. Firs build the container and then you can run the script.