2. JTI - docker-compose

Goals

The goals for this exercise is to continue on "JTI - Docker" by adding Docker-compose to orchestrate our docker containers. After we are done, we will still be able to work on our application locally, through the docker containers.

Prerequisites

You should by now have completed "1. JTI - Docker" and you can continue to work in the same repository if you like.

Make sure to watch the Demo #5 during this exercise.

Stop and remove the containers and images created during the previous exercise.

1. Docker-compose

Follow the guide (Demo #5) with the following in mind:

  • We want to mount a volume between our local src-folder, and the src-folder in the container on the same way as in the previous exercise. But we want to do it generic so that the path is not dependent on our local operating system.

Some things to note or help you on the way:

  • When using volumes in the docker-compose.yaml, we can write relative paths. I.e: ./src:/usr/src/app/src
  • Make sure to create a volume for mongodb as well. Se dockerhub->mongo for more information. Place the volume in your repository under .volumes/mongodb and make sure to add .volumes to your .gitignore.
  • When using docker-compose, you do not need to specify networks. Docker-compose will automaticly create one for you.
  • For your conveniency, you can add the line "docker:dev": "docker-compose up --build", to your "scripts"-section in package.json to be able to start easy with: npm run docker:dev

Test it!

Visit http://localhost:8080 and the application should be up and running.

No you should be able to change files in the src-folder on your local machine, nodemon in the container will see this and the application restarts. Reload the browser to confirm that changes to, for example, the front page are visible.

Next step

Yay! We can now develop using containers in a very convinient way! Lets put the code into production --->