Skip to content

Install & config guide: Docker

Needed at M11 (to containerize your app). A container bundles your app and its exact dependencies into one image that runs the same on any machine, "it works on my laptop" becomes "it works everywhere." (You met containers in Course 01.) Docker is the tool that builds and runs them.

Don't have time/space for Docker? You can still finish M11 without it, run your app with uvicorn app:app (a real web server) and share it. Docker is the "ship it properly" step; the lab has a no-Docker fallback.

Official docs (verify they open): https://docs.docker.com/get-started/get-docker/.


Step 1: Install Docker

Windows / macOS

Install Docker Desktop from https://www.docker.com/products/docker-desktop/ (it includes the Docker engine and a dashboard). Run the installer, then launch Docker Desktop and wait for the whale icon to say "running." (Windows: it may ask to enable WSL 2, accept.)

Linux (Debian/Ubuntu)

Install Docker Engine following the official guide (https://docs.docker.com/engine/install/), then allow your user to run it:

sudo usermod -aG docker $USER    # then log out and back in

You should now see: Docker Desktop running (Win/Mac), or docker available in your terminal (Linux).

Step 2: Check it worked

docker run hello-world
You should now see: a message starting "Hello from Docker!", confirming Docker can pull and run an image. If you see that, you're ready.

Step 3: Build your app's image

From the folder with your Dockerfile, app.py, and requirements.txt:

docker build -t ai-app .
You should now see: build steps ending in naming to docker.io/library/ai-app (or Successfully tagged ai-app). Your app is now an image.

Step 4: Run it (passing your key safely)

docker run -p 8000:8000 --env-file .env ai-app
You should now see: Uvicorn running on http://0.0.0.0:8000. Open http://127.0.0.1:8000/docs in your browser and try the endpoint. (--env-file .env passes your API key at run time; it's never baked into the image, .dockerignore keeps .env out of the build.)


Troubleshooting

Symptom Fix
docker: command not found Docker Desktop isn't installed/running (Win/Mac), or (Linux) the engine isn't installed. Start Docker Desktop and wait for "running."
Cannot connect to the Docker daemon The Docker engine isn't up, launch Docker Desktop (Win/Mac); on Linux sudo systemctl start docker.
Linux: permission denied on docker ... You're not in the docker group, run the usermod line in Step 1, then log out and back in.
Build fails installing packages Usually a typo in requirements.txt, or no internet during build.
App starts but calls fail with 401 You didn't pass the key, use --env-file .env, and make sure .env has your real ANTHROPIC_API_KEY.

Secrets at deploy time. Never bake an API key into an image (anyone with the image could read it). Pass it at run time with --env-file .env (or your host's secrets manager). Keep .env in .dockerignore and .gitignore.