The purpose of this repository is to show how you can build a Docker image for a Node.js + TypeScript app with the Docker multi-stage feature, available since version 17.05.
- Install dependencies:
npm install
- Start the app:
npm start
- Call the greeting endpoint:
curl http://localhost:3000/greeting\?name\=John
{"id":"76ac792c-c1a9-4fc5-ba75-39652a06b381","message":"Hello, John!"}
To build the Docker image, use the docker build
command:
docker build . -t greeting-service:latest
To stop the build on a specific stage, use the target
option:
docker build --target builder -t greeting-service:latest .
To run the Docker image, use the docker run
command:
docker run -p 3000:3000 --rm greeting-service:latest
Then, you can invoke the greeting service running in a Docker container with:
curl http://localhost:3000/greeting\?name\=Docker
{"id":"7af0385b-99dc-4d47-a423-f6ab18ea7f1c","message":"Hello, Docker!"}
Contributions are welcome!
Submit an issue or a pull request if you want to contribute some code.