2. JTI - Docker Compose

Goals

The goal of this exercise is to build upon "JTI - Docker" by incorporating Docker Compose to orchestrate your Docker containers. Once completed, you'll be able to work on your application locally, but through Docker containers.

Prerequisites

By now, you should have completed the first step, "1. JTI - Docker". You can continue to work in the same repository if you prefer.

Ensure you watch Demo #5 during this exercise.

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

1. Docker Compose

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

  • Your aim is to mount a volume between your local src folder and the src folder in the container, similar to the previous exercise. However, it should be done in a generic way so that the path is not dependent on your local operating system.

Here are some tips and things to note:

  • When using volumes in the docker-compose.yaml file, you can write relative paths, e.g., ./src:/usr/src/app/src.
  • Create a volume for MongoDB as well. See the official MongoDB image mongo on Docker Hub for more information. Place the volume in your repository under .volumes/mongodb and add .volumes to your .gitignore file.
  • With Docker Compose, you don't need to specify networks. Docker Compose will automatically create one for you.
  • For convenience, add the line "docker:dev": "docker compose up --build", to your scripts section in package.json. This allows you to start easily with: npm run docker:dev.

Test it!

Open your web browser and visit [http://localhost:8080]. The application should be up and running.

You should now be able to modify files in the src folder on your local machine. nodemon in the container will detect these changes and restart the application. Refresh your browser to confirm that changes to the front page are visible.

Next step

Great job! Now, you can develop using containers in a very convenient way! The next step is to put the code into production. This involves deploying your application so that it's accessible to end users.

Proceed to the next step