DEV Community

Why Docker? Creating a multi-container application with docker

Samuel James on May 05, 2018

If you are just starting to learn docker, one of the common questions that come to mind is what docker is and why one would need it. In this pos...
Collapse
 
suprnova32 profile image
Patricio Cano
Collapse
 
abiodunjames profile image
Samuel James

:) I love this.

Collapse
 
bacchusplateau profile image
Bret Williams

One of the clearest and most concise "Docker 101" articles I've come across. Thanks!

Collapse
 
nicosouv profile image
Nicooo

Very good post!

Since you build all the services in the same docker-compose (so, in the same network), all services should be able to talk to each other, so you might not need the "link" in your docker-compose.yml.
I think. I may have to check that though ;)

Collapse
 
azazqadir profile image
Muhammad Azaz Qadir

For deploying php apps on a docker multi container, the process is not really that difficult. Once you have setup the environment, you have to add docker compose yml file to your project root.

Source: dockerize php application

Collapse
 
r0bnet profile image
rob

Nice introduction. I missed two things that may not be clear for beginners.

  1. The image shows 5 containers (or container like objects) but there are only 4. The app is included via volumes. That confused me when i saw the pic but i got it when i read the article.
  2. I think you forgot to explain the "links" statement as part of the web container. With that it's possible to directly address the app container in the nginx config.

Keep going! :)

Collapse
 
abiodunjames profile image
Samuel James • Edited

Thank you for the comment. I'll update it shortly.

Collapse
 
lumayara profile image
Luana Mayara Fernandes da Silva Bezerra

Hi Samuel! Thank you so much for your article! It worked here the only little container that didnt run was Mysql.. I kept getting this error:

W: Failed to fetch deb.debian.org/debian/dists/jessie... Unable to find expected entry 'main/binary-amd64/Packages' in Release file (Wrong sources.list entry or malformed file)

E: Some index files failed to download. They have been ignored, or old ones used instead.

So it wasn't working and I saw someone on github said to put this code before RUN apt-get update: RUN sed -i '/jessie-updates/d' /etc/apt/sources.list

and I did and the rest of the stuff worked however I didnt get the MySQL instance running.. no idea why as I am super new to docker...
Could you help me?

Thanks!

Collapse
 
tylerlwsmith profile image
Tyler Smith

Thanks for writing this article!

Do you have any advice regarding when to use docker-compose vs when to use a Dockerfile and programmatically install the individual services into one container?

Collapse
 
abiodunjames profile image
Samuel James • Edited

Hi Tyler,
Thanks for reading.

A container is standardized unit of software which is lightweight, standalone while Docker Compose provides a way to orchestrate multiple containers (applications) that work together.
In a real-world, you may need more than one components (application) to run a software. For example: a software may need many components like database, webserver, cache server, and more to run. Each of these components is a unit.
When you have multiple components to deal with, you should use docker-compose to orchestrate them.

Don't package everything into a single container. A container is a unit of software.

Collapse
 
tylerlwsmith profile image
Tyler Smith

"A container is a standardized unit of software."

That's a killer way to describe containers, thank you for your insight! I've been spending the day wrangling with docker-compose and was wondering if I was crazy for not just using a single Dockerfile.

Collapse
 
bengreenberg profile image
Ben Greenberg

This is great! I've been interested in exploring Docker for a while and found what you wrote to be a really accessible entry into it, thanks for this.

Collapse
 
abiodunjames profile image
Samuel James

I'm happy you find it useful.

Collapse
 
falansari profile image
Ash

This really demystified docker for me. Thanks for that!

Collapse
 
abiodunjames profile image
Samuel James

Thanks for reading. I'm glad you find it helpful.