Calvin Goodale, Developer - Blog
c g o o d a a l e . . c o m

Hack Reactor | SDC | Journal Entry 7

Overview
Docker set up for express server and mongo

Challenge/Motivation
I decided to get some practice in with Docker locally

Actions Taken

  1. Create a network for both containers to use:
    docker network create network-sdc
  2. 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
  3. Create the node server Docker image:
    sudo docker build . -t node-sdc
  4. 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
  5. Check that both containers are running:
    sudo docker containers ls -a
  6. Check log file for node server container:
    sudo docker logs node-sdc
  7. 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