

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Dockerfiles
incomplete
2: Building a Server
incomplete
3: Dockerizing the Server
incomplete
4: Creating an Environment
incomplete
5: Python Script
incomplete
6: Dockerizing Python Error
incomplete
7: Dockerizing Python
incomplete
This lesson's interactive features are locked, please to keep using them
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 python interpreter installed, so it can't run the script.
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...
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.
# Build from a slim Debian/Linux image
FROM debian:stable-slim
# Update apt
RUN apt update
RUN apt upgrade -y
# Install build tooling
RUN apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
# Download Python interpreter code and unpack it
RUN wget https://www.python.org/ftp/python/3.10.8/Python-3.10.8.tgz
RUN tar -xf Python-3.10.*.tgz
# Build the Python interpreter
RUN cd Python-3.10.8 && ./configure --enable-optimizations && make && make altinstall
# Copy our code into the image
COPY main.py main.py
# Copy our data dependencies
COPY books/ books/
# Run our Python script
CMD ["python3.10", "main.py"]