| Variable de entorno | valor | descripción |
|---|---|---|
| MONGO_USERNAME | dbuser | Username for mongoDB |
| MONGO_PASSWORD | algun-password | password for db |
| MONGO_DB_NAME | apiMongoDB | Name of db to use |
| JWT_SECRET | AlgunValorSecreto | Secret to configure hash of login tokens |
| SALT_ROUNDS | 10 | Numeric value to configure the encrypt for password when creating and saving a new user. |
To run this app using docker it would be necessary to create a folder with two files:
In the .env file is where you will put the environment variables described up here. And in the docker-compose.yaml file is where you will configure the mongodb service that is required in order to the app works properly.
You can run this Image with the docker run command, but it is more easy doing it with the docker compose file since you need to configure the env variables and the mongodb service.
Here are examples for this files:
| .env |
|---|
MONGO_PASSWORD=12345
MONGO_DB_NAME=test-api-mongo
JWT_SECRET=ThisIsMyJwtSecret125463156135
SALT_ROUNDS=10
| docker-compose.yaml |
|---|
services:
app:
image: carlosempd/test-nestjs-api
depends_on:
- db
ports:
- 3000:3000
environment:
- MONGO_USERNAME=${MONGO_USERNAME}
- MONGO_PASSWORD=${MONGO_PASSWORD}
- MONGO_DB_NAME=${MONGO_DB_NAME}
- JWT_SECRET=${JWT_SECRET}
- SALT_ROUNDS=${SALT_ROUNDS}
db:
image: mongo:5
container_name: ${MONGO_DB_NAME}
restart: always
ports:
- 27017:27017
environment:
- MONGODB_DATABASE=test-mongo-api
- MONGO_INITDB_ROOT_USERNAME=${MONGO_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}
volumes:
- mongo-test:/data/db
command: ['--auth']
volumes:
mongo-test:
external: false
Finally, open a terminal inside the folder created with the two files metioned above and run:
docker compose up
This will download this image with the latest version (unless you specify one) and the mongo image and will mount the container with the app running.
After that, open in the browser http://localhost:3000/apiā and you should be able to see the endpoints via swagger documentation.
Content type
Image
Digest
sha256:4337e9245ā¦
Size
62.3 MB
Last updated
over 3 years ago
docker pull carlosempd/test-nestjs-api