Running the Stack
We now have a compose.yaml file that describes both services.
Time to cash in.
Instead of launching containers one at a time with a pile of manual commands, we can now ask Docker Compose to bring the whole stack up for us.
Starting the Stack
Section titled “Starting the Stack”From the folder containing compose.yaml, run:
docker compose upCompose will read the file, build what needs to be built, pull what needs to be pulled, create the network, and start the services.
That is already a lot less nonsense than the manual approach.
Foreground Is for Learning
Section titled “Foreground Is for Learning”By default, docker compose up keeps the logs attached to our terminal. This is exactly what we want right now.
We can watch both services start in real time and, more importantly, spot connection issues immediately as they scroll past.
When we are still figuring out what is happening, attached logs are our friend.
They make the system feel much less mysterious.
What We Should Expect
Section titled “What We Should Expect”If this is our first run, Compose may need a moment to:
- build the API image
- download the MongoDB image
- create the containers
- create the network
Once the logs settle and we see the API is listening, we can test it at:
http://localhost:3000/api/projectsIt Works, But It Is Brittle
Section titled “It Works, But It Is Brittle”At this point, Compose has made startup much easier.
But we still have one important issue floating around in the background:
- Our app code is still hardcoded to connect to MongoDB in a way that belongs in configuration, not in source code.
So yes, Compose improves orchestration immediately.
But no, we are not fully cleaned up yet.
Compose can start the stack beautifully, but it does not magically fix bad configuration choices inside our app.
If important values are still hardcoded, we still have work to do.
Next Steps
Section titled “Next Steps”Now that we have seen the power of “one command to rule them all,” we need to make that command smarter by stripping out the hardcoded secrets and connection strings.
Extra Bits & Bytes
Section titled “Extra Bits & Bytes”Docker Compose Up Reference
⏭ Services & Environment
Section titled “⏭ Services & Environment”Compose now manages the stack, but our configuration still needs work. Next, we’ll clean up service settings and move important values into environment-based config.