Q&A 7 How do you get started with Docker before containerizing your model?

7.1 Explanation

Docker is a tool that lets you package your application β€” including code, dependencies, and environment β€” into a portable container. Containers run the same way across laptops, servers, and the cloud, making them perfect for deploying machine learning APIs.

Before containerizing your FastAPI model, you should first:

  • Understand what Docker is
  • Install and start Docker Desktop
  • Build and run a basic Docker image

7.2 Step 1: Install Docker Desktop

πŸ‘‰ Download Docker for Mac
πŸ‘‰ Download Docker for Windows

Install it like any other application.


7.3 Step 2: Start Docker Desktop

After installation:

  • Mac: Open Docker from Launchpad or the Applications folder
  • Windows: Open Docker Desktop from the Start menu

You should see the 🐳 Docker whale icon appear in your menu bar or system tray.

βœ… Wait for the message ➑️ Docker is running


7.4 Step 3: Confirm Docker is Active

In your terminal, run:

docker info

You should see details like Docker version, containers, and storage. If you see an error like:

Cannot connect to the Docker daemon…

That means Docker is not running β€” go back and start Docker Desktop.

7.5 Step 4: Write Your First Dockerfile

Create a folder named hello-docker, and inside it create a Dockerfile:

FROM python:3.12-slim

WORKDIR /app

COPY . .

CMD ["python3", "-c", "print('πŸŽ‰ Hello from Docker!')"]

7.6 Step 5: Build and Run Your First Container

docker build -t hello-docker .
docker run hello-docker

You should see:

πŸŽ‰ Hello from Docker!

7.7 Step 6: Log in to Docker Hub

Before pushing images or scanning them, log in:

docker login

You can use:

  • Your Docker ID or email
  • Your password (not recommended)
  • Or a Personal Access Token (PAT) (recommended)

πŸ” Create a PAT here

Using a PAT is required if:

  • You have 2FA enabled
  • You’re part of an organization using SSO
  • You want better security

7.8 Step 7: Tag and Push Your Image

After login:

docker tag hello-docker yourusername/hello-docker
docker push yourusername/hello-docker

This makes your image accessible from the cloud or collaborators.

7.9 Step 8: Scan Your Image with Docker Scout (Optional)

After building an image, Docker may suggest:

View a summary of image vulnerabilities and recommendations β†’ docker scout quickview

docker scout quickview

Docker Scout checks for:

  • Vulnerabilities in your base image
  • Outdated dependencies
  • Upgrade suggestions

Make sure you’re logged in before using Scout

7.10 Example Log Insights

  • Cannot connect to the Docker daemon…
    • β†’ Start Docker Desktop first and retry.
  • Using a limited-scope PAT grants better security..
    • β†’ Prefer PATs for login over full passwords.

βœ… Takeaway: Understanding Docker basics β€” installation, login, and image scanning β€” prepares you for robust, secure ML model deployment and reproducibility..