Build and Run a Local Service Image
Package a service into a container, tag it, and start it for local testing.
Steps
-
Ensure your Dockerfile is at the project root.
-
Build the image with a meaningful tag.
docker build -t todo-api:dev . -
Run the container with mounted environment files or ports as needed.
docker run --rm -it -p 3000:3000 --env-file .env.todo todo-api:dev -
Stop the container with Ctrl + C when finished; add the
--detachflag for background execution.
Verification
docker psshows the container running.- Your service responds on the mapped port.