1.2.1 - Introduction to Docker
Last updated Jan 22, 2025
Youtube Video | ~24 min
✍️ In this video, we learn about what Docker is, get a pipeline overview, and learn about Docker container and Docker image. Then we work through an example of how to build an image with Docker.
⚒️ There is a supplemental video for those working on WSL found here: https://www.youtube.com/watch?v=Mv4zFm2AwzQ&list=PL3MmuxUbc_hJed7dXYoJw8DoCuVHhGEQb&index=17
What is...
"Docker helps developers build, share, run, and verify applications anywhere — without tedious environment configuration or management." - https://www.docker.com/
"Simply put, containers are isolated processes for each of your app's components. Each component - the frontend React app, the Python API engine, and the database - runs in its own isolated environment, completely isolated from everything else on your machine." - https://docs.docker.com/get-started/docker-concepts/the-basics/what-is-a-container/
"If you’re new to container images, think of them as a standardized package that contains everything needed to run an application, including its files, configuration, and dependencies. These packages can then be distributed and shared with others." - https://docs.docker.com/get-started/introduction/build-and-push-first-image/
"A tag is a custom, human-readable identifier that's typically used to identify different versions or variants of an image. If no tag is specified, latest is used by default." - https://docs.docker.com/get-started/docker-concepts/building-images/build-tag-and-publish-an-image/
Building a Container Image
Example code you want to deploy
import sys
import pandas as pd
print(sys.argv)
day = sys.argv[1]
# some pandas things
print(f'Finished for day {day}')from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"Dockerfile
📝 Create a new 'Dockerfile' in your code editor. I recommend adding the Docker 'plug in' to your editor.
FROM python:3.12.8
RUN pip install pandas
WORKDIR /app
COPY pipeline.py pipeline.py
ENTRYPOINT ["python", "pipeline.py"]# syntax=docker/dockerfile:1
FROM ubuntu:22.04
# install app dependencies
RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip install flask==3.0.*
# install app
COPY hello.py /
# final configuration
ENV FLASK_APP=hello
EXPOSE 8000
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "8000"]🔖 https://docs.docker.com/reference/dockerfile/ - Dockerfile Instruction options i.e. 'FROM', 'RUN', etc.
Docker build
⬛ Terminal
docker build -t {image_name}:{tag_name} .used to denote adding a tag
replace these values for your image_name and tag_name
a build command that uses the current directory (.) as a build context
👀 Note we will continue to build on this topic. We still need to talk about running containers, stopping containers, and viewing the front end of our containers.
🧹 Cleaning - be sure to open Docker Desktop and delete testing examples of your containers and images to free up space
Resources
My repo for this video can be found here
🔖 https://docs.docker.com/get-started/docker-overview/
🔖 https://github.com/HangenYuu/docker-cheatsheet
📚 I recommend working through the Docker site Intro & workshop if you're still confused on what Docker is
Last updated