![]() |
VOOZH | about |
In the last tutorial, How to Install and Configure Docker, we explored one method for converting Docker containers into Docker images. Although the method we used worked, it is not always the optimal way of building images.
In many cases, youโll want to bring existing code into container images, and youโll want a repeatable, consistent mechanism for creating Docker images that are in sync with the latest version of your codebase.
A Dockerfile addresses these requirements by providing a declarative and consistent way of building Docker images.
Additionally, youโll sometimes want to containerize entire applications which are composed of multiple, heterogeneous containers that are deployed and managed together.
Docker Compose, like a Dockerfile, takes a declarative approach to provide you with a method for defining an entire technology stack, including network and storage requirements. This not only makes it easier to build containerized applications, but it also makes it easier to manage and scale them.
In this tutorial, you will use a sample web application based on Node.js and MongoDB to build a Docker image from a Dockerfile, you will create a custom network that allows your Docker containers to communicate, and you will use Docker Compose to launch and scale a containerized application.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This series covers the essentials of containers, including container lifecycle management, deploying multi-container applications, scaling workloads, and understanding Kubernetes, along with highlighting best practices for running stateful applications. These tutorials supplement the by the same name.
Browse Series: 6 tutorials
Cloud Computing Enthusiast
Technical Editor @ DigitalOcean
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Nice tutorial! Thanks for sharing ^_^
I got an error with web container unable to connect to mongo db container port:27017, which resulted in web container exiting. so I have to add expose statement to the db service : db: 4 image: mongo:latest 5 expose : 6 - โ27017โ 7 container_name: db 8 networks: 9 - todonet
You may need to add this in your Dockerfile to test if the web container is connected to the db container with ping.
RUN apt-get update && apt-get install -y iputils-ping
Very useful tutorialโฆ Thank you very much. Hope you update it by using the latest versions of docker and docker-compose.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.