We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dockerizing Python

Okay, so our first attempt at Dockerizing the Python script didn't work... let's fix it!

The problem is our image doesn't have the python3 interpreter installed, so it can't run the script.

Assignment

  1. docker build -t bookbot -f Dockerfile.py .
    
    It might take a few minutes to build the image... we're installing an entire Python interpreter after all!

    Maybe now you can see why I like Go so much...

  2. docker run bookbot
    

If Bookbot ran, then you did it correctly! We've bundled up the Python script, its required data, and its required runtime all into a nice little container image!

Run and submit the CLI tests.

Common technologies often have images available for ease of use. See the Python Official Image from DockerHub Official Images.

Tip

# Build from a slim Debian/Linux image
FROM debian:stable-slim

RUN apt-get update && apt-get install -y python3

# Copy our code into the image
COPY main.py main.py

# Copy our data dependencies
COPY books/ books/

# Run our Python script
CMD ["python3", "main.py"]