Using docker
Docker is a technology which allows you to run your Vendure application inside a container.
The default installation with @vendure/create includes a sample Dockerfile:
This Dockerfile can then be built into an "image" using:
This same image can be used to run both the Vendure server and the worker:
Here is a breakdown of the command used above:
docker run- run the image we created withdocker build-dp 3000:3000- the-dflag means to run in "detached" mode, so it runs in the background and does not take control of your terminal.-p 3000:3000means to expose port 3000 of the container (which is what Vendure listens on by default) as port 3000 on your host machine.--name vendure-server- we give the container a human-readable name.vendure- we are referencing the tag we set up during the build.npm run start:server- this last part is the actual command that should be run inside the container.
Docker Compose
Managing multiple docker containers can be made easier using Docker Compose. In the below example, we use the same Dockerfile defined above, and we also define a Postgres database to connect to:
Kubernetes
Kubernetes is used to manage multiple containerized applications. This deployment starts the shop container we created above as both worker and server.
Health/Readiness Checks
If you wish to deploy with Kubernetes or some similar system, you can make use of the health check endpoints.
Server
This is a regular REST route (note: not GraphQL), available at /health.
Health checks are built on the Nestjs Terminus module. You can also add your own health checks by creating plugins that make use of the HealthCheckRegistryService.
Worker
Although the worker is not designed as an HTTP server, it contains a minimal HTTP server specifically to support HTTP health checks. To enable this, you need to call the startHealthCheckServer() method after bootstrapping the worker:
This will make the /health endpoint available. When the worker instance is running, it will return the following: