Run and Test the Container Locally
Build, run, and hit the endpoint from your machine.
Run and Test the Container Locally is a free MLOps Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the MLOps Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Run It Locally First
Before shipping, run the container on your own machine. Catching bugs locally is far cheaper than debugging them in the cloud.
Start the Container
Launch the image with docker run. Without port mapping it runs, but nothing on your host can reach the API inside.
docker run model-apiMap the Port
The -p flag maps a host port to the container port. Now localhost:8000 reaches the model API serving inside.
docker run -p 8000:8000 model-apiRun in the Background
Add -d to detach and run in the background. Your terminal stays free while the service keeps serving.
docker run -d -p 8000:8000 model-apiList Running Containers
See what is up with docker ps. It shows each container ID, its image, status, and the ports it has mapped.
docker psHit the Health Check
Confirm the service is alive by calling its /health endpoint. A 200 response means it is ready to take predictions.
curl http://localhost:8000/healthSend a Prediction
POST a sample payload to /predict and read the result. This proves the model loads and responds end to end.
curl -X POST http://localhost:8000/predict -d '{"x": [1, 2, 3]}'Read the Logs
When something looks off, check docker logs. The container prints startup errors and stack traces straight to its log stream.
docker logs <container_id>Shell Inside
Open a shell in a running container with docker exec to inspect files or the environment from within.
docker exec -it <container_id> /bin/bashStop and Clean Up
Finish by stopping the container with docker stop. Add --rm at run time so it is removed automatically when it exits.
docker stop <container_id>Test Before You Push
If it runs clean and answers correctly here, it will behave the same in the cloud. Local testing is your last safe gate.
Quick Check
Let us check how you reach the API from your host.
Recap
You ran the image, mapped the port, checked health, sent a prediction, read logs, and cleaned up. Your container is deploy-ready. 🐳
Frequently asked questions
Is the “Run and Test the Container Locally” lesson free?
Yes — the full text of “Run and Test the Container Locally” is free to read here on the web, and the MLOps Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the MLOps Academy course, upgrade to CoddyKit PRO.
What will I learn in “Run and Test the Container Locally”?
Build, run, and hit the endpoint from your machine. You practise MLOps Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start MLOps Academy?
No prior experience is required. MLOps Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Run and Test the Container Locally” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this MLOps Academy lesson?
Yes. Every MLOps Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Write a Dockerfile for a Model API
- Slim Images with Multi-Stage Builds
- Pass Config via Environment Variables
- Run and Test the Container Locally