Docker Compose
Docker Compose
Prerequisites:
Lab Exercise: In this exercise, students will create a basic multi-container application
using Docker Compose. The application will consist of two services: a web server and
a database.
Instructions:
1. Setup:
o Make sure Docker is installed on your system.
o Create a new directory for your project.
o Inside the project directory, create two files: Dockerfile and docker-
compose.yml .
2. Create Dockerfiles:
o Write Dockerfiles for both services (web server and database).
o For example, for a simple Node.js web server:
3. Write docker-compose.yml:
o Create a docker-compose.yml file to define the services.
o Here's an example for a Node.js web server and a MongoDB database:
4. Build and Run the Application:
o Run the following command in the project directory to build and run
the application:
docker-compose up
o This command will start both services defined in the docker-
compose.yml file.
5. Access the Application:
o Access the web server from a web browser at
http://localhost:3000 .
o You can interact with the application to see how it communicates with
the database.
6. Cleanup:
o After you're done, stop the running containers by pressing Ctrl + C .
o Optionally, you can run docker-compose down to remove the
containers.
Discussion Questions: