Setting up the Environment
13%
The Container Image
Let's create a Docker image for our to-do application. We start by creating a Dockerfile. Use the following command to create the file:
cat << EOF > $HOME/todo/app/Dockerfile
# Use an official Python runtime as a parent image
FROM python:3.12-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . .
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Make port 5000 available to the world outside this container
EXPOSE 5000
# Define environment variable
CMD ["python", "app.py"]
EOF
Create a .dockerignore file to exclude unnecessary files from the Docker build context:
cat << EOF > $HOME/todo/app/.dockerignore
.git
.gitignore
__pycache__
venv
tests
Dockerfile
EOF
Install Docker:
# Download the Docker installation script (V29)
curl -fsSL https://get.docker.com -o install-docker.sh
# Run the Docker installation script
sh install-docker.sh --version 29
# Remove the installation script
rm install-docker.sh
Build the image using the following command:
docker build -t todo-app $HOME/todo/app
Helm in Practice
Designing, Deploying, and Operating Kubernetes Applications at ScaleEnroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!
Unlock now  $15.99$11.99Learn More
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
