• Shopping Cart Shopping Cart
    0Shopping Cart
London App Developer
  • Courses
  • Consulting
  • Tutorials
  • About
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
Docker compose and Docker logos on a thumbnail
Docker

Docker vs Docker Compose, what’s the difference?

This is a question asked by a student who is taking our course: Build a Backend REST API with Python & Django – Advanced.

Question

A student asked: What is the difference between Docker and Docker Compose? Why do we need both a Dockerfile and docker-compose.yml file in the project?

Answer

When working with Docker, there are two concepts: Image and Container.

Images are like mini operating systems stored in a file which is built specifically with our application in mind. Think of it like a custom operating system which is sitting on your hard disk when your computer is switched off.

Containers are running instances of your image.

Imagine you had a shared hard disk (or even CD/DVD if you are old school) which had an operating system which can run on multiple machines. The files on the disk are the “image”, and those files running on a machine are a “container”.

This is how Docker works, you have files on the machine which are known as the image, and running instances of those files are referred to as the container. Images can also be uploaded and shared for other users to download and run on their machine too.

This brings us to Docker vs Docker Compose.

Docker is the underlying technology which manages (creates, stores or shares) images, and runs containers.

We provide the Dockerfile to tell Docker how to create our images. For example, we say: starts from the Python 3 base image, then install these requirements, then creates these folders, then switch to this user, etc… (I’m oversimplifying the actual steps, but this is just to explain the point).

Once we have done that, we can create an image using Docker, by running docker build .. If you run that, Docker will execute each step in our Dockerfile and store the result as an image on the system.

Once the image is build, you can run it manually using something like this:

docker run <IMAGE_ID>

However, if you need to setup volumes, you need to run them like this:

docker run -v /path/to/vol:/path/to/vol -p 8000:8000 <IMAGE_ID>

Often applications need multiple images to run. For example, you might have an application and a database, and you may also need to setup networks and shared volumes between them.

So you would need to write the above commands with the appropriate configurations and ID’s for each container you want to run, every time you want to start your service…

As you might expect, this could become complex, tedious and difficult to manage very quickly…

This is where Docker Compose comes in…

Docker Compose is a tool used to define how Docker runs our images in a yaml file which is can be stored with our code and reused.

So, if we need to run our app image as a container, share port 8000 and map a volume, we can do this:

services:
  app:
    build:
      context: .
    ports:
      - 8000:8000
    volumes:
      - app/:/app

Then, every time we need to start our app, we just run docker-compose up, and Docker Compose will handle all the complex docker commands behind the scenes.

So basically, the purpose of Docker Compose is to configure how our running service should work together to serve our application.

When we run docker-compose build, Docker Compose will run all the necessary docker build commands, to build all images needed for our project and tag them appropriately to keep track of them in the system.

In summary, Docker is the underlying technology used to create images and run them as containers, and Docker Compose is a tool that configures how Docker should run multiple containers to serve our application.

Tags: Docker, Docker Compose
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://i0.wp.com/londonappdeveloper.com/wp-content/uploads/2021/07/Docker-vs-docker-compose.png?fit=606%2C474&ssl=1 474 606 mark https://londonappdeveloper.com/wp-content/uploads/2018/12/lon_website_logo-300x110.png mark2021-07-06 22:19:182021-07-06 22:19:21Docker vs Docker Compose, what’s the difference?
You might also like
Add Backend to React with Django REST Framework and Docker
Dockerizing a Django REST Framework Project
Setting up PostgreSQL database with a Django Docker application
Docker and VSCode logos on an orange background Use Docker to create a new Django project in one line
Docker and Travis CI logos with a caution sign Fixing toomanyrequests error when using Docker with Travis-CI
Blog title with AWS Terraform and Docker logos How to use Terraform via Docker Compose for Pros
Django and Docker compose logos on a blueish green background Deploying Django with Docker Compose
Django Docker Deployment with HTTPS using Letsencrypt
1 reply
  1. temo2ginal
    temo2ginal says:
    June 21, 2022 at 8:36 am

    The best explanation I could find on the web. TY

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Pages

  • About
  • Consulting
  • Home
  • Tutorials

Categories

  • AI
  • Android
  • Android Studio
  • Angular
  • Aptana Studio
  • AWS
  • Bootstrap
  • Career advice
  • Celery
  • Databases
  • Deployment
  • DevOps
  • Django
  • Django REST Framework
  • Docker
  • Eclipse
  • Getting Help
  • Git
  • Git Bash
  • Git Flow
  • GitHub Actions
  • Google App Engine
  • IDE
  • Ionic Framework
  • iOS
  • JavaScript
  • Job Search
  • Links
  • Linux
  • Mac OS X
  • macOS
  • Node.JS
  • OpenAI
  • PGAdmin
  • Postgres
  • Productivity
  • Python
  • React
  • Salt Stack
  • Stack Overflow
  • Tools
  • Travis-CI
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Vagrant
  • VSCode
  • WebSockets
  • Windows 10
  • WordPress

London App Developer Ltd,

71-75 Shelton Street, Covent Garden, London, United Kingdom, WC2H 9JQ

Company registration number: 09718346

© London App Developer - London App Developer Ltd, Company Registration Number: 09718346, VAT: GB224061842
  • Link to X
  • Link to Youtube
  • Link to Facebook
  • Link to Reddit
Link to: Deploying Django with Docker Compose Link to: Deploying Django with Docker Compose Deploying Django with Docker ComposeDjango and Docker compose logos on a blueish green background Link to: Django Docker Deployment with HTTPS using Letsencrypt Link to: Django Docker Deployment with HTTPS using Letsencrypt Django Docker Deployment with HTTPS using Letsencrypt
Scroll to top Scroll to top Scroll to top

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.

OKLearn more

Cookie and Privacy Settings



How we use cookies

We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

Essential Website Cookies

These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

Google Analytics Cookies

These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.

If you do not want that we track your visit to our site you can disable tracking in your browser here:

Other external services

We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

Google Webfont Settings:

Google Map Settings:

Google reCaptcha Settings:

Vimeo and Youtube video embeds:

Other cookies

The following cookies are also needed - You can choose if you want to allow them:

Privacy Policy

You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

Privacy Policy
Accept settingsHide notification only