Build and Run the Docker Container
Build the Docker image from the project root.
Run:
docker build -t nodejs-rest-api .
Start the container:
docker run -d \
--name rest-api \
-p 3000:3000 \
--env-file .env \
nodejs-rest-api
The application will be accessible at:
For this local demonstration, .env contains the required configuration. In production, use your deployment platform's secret management rather than copying development credentials into a container.
Build and Run Docker Image
docker build -t nodejs-rest-api .
docker run -d --name rest-api -p 3000:3000 --env-file .env nodejs-rest-apiBuilds the image and starts a container with port 3000 exposed.
Key Takeaways
docker build creates the container image.
docker run starts the application container.
Environment variables configure the running application.