Build and Run a Local Service Image

Package a service into a container, tag it, and start it for local testing.

Steps

  1. Ensure your Dockerfile is at the project root.

  2. Build the image with a meaningful tag.

    docker build -t todo-api:dev .
  3. 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
  4. Stop the container with Ctrl + C when finished; add the --detach flag for background execution.

Verification

  • docker ps shows the container running.
  • Your service responds on the mapped port.