Hack Reactor | SDC | Journal Entry 7
Categories: hack reactor SDC docker
Overview
Docker set up for express server and mongo
Challenge/Motivation
I decided to get some practice in with Docker locally
Actions Taken
- Create a network for both containers to use:
docker network create network-sdc
- Create the mongodb container:
sudo docker run --name mongo-sdc -d --network network-sdc -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=<password> -v <your-local-mongodb-data-path>:/data/db mongo
- Create the node server Docker image:
sudo docker build . -t node-sdc
- Create the node server Docker container:
sudo docker run --name node-sdc -p 49160:3030 --network network-sdc -d -e DB_PASSWORD='<db-password-in-env-file>' node-sdc
- Check that both containers are running:
sudo docker containers ls -a
- Check log file for node server container:
sudo docker logs node-sdc
- Curl to an API server route to make sure expected data is returned:
curl -i localhost:49160/products/1
Results Observed
The most challenging parts were figuring out how to enable authentication for the mongo database in the context of Docker (which required initializing the database with with a root user and password) and making sure to add the password from my .env file intot he container, and also figuring out that I needed both containers to be in the same network.
0 Comments