Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Docker Compose vs. Dockerfile [closed]

I have been reading up and learning about Docker, and am trying to correctly choose the Django setup to use. So far there is either:

Docker Compose or Dockerfile

I understand that Dockerfiles are used in Docker Compose, but I am not sure if it is good practice to put everything in one large Dockerfile with multiple FROM commands for the different images?

I want to use several different images that include:

uwsgi nginx postgres redis rabbitmq celery with cron 

Please advise on what are best practices in setting up this type of environment using Docker.

If it helps, I am on a Mac, so using boot2docker.

Some Issues I've had:

  1. Docker Compose is not compatible with Python3
  2. I want to containerize my project, so if one large Dockerfile is not ideal, then I feel I'd need to break it up using Docker Compose
  3. I am ok to make the project Py2 & Py3 compatible, so am leaning towards django-compose
like image 273
Aaron Lelevier Avatar asked Apr 06 '15 21:04

Aaron Lelevier


People also ask

Do I need Dockerfile if I use Docker compose?

Docker compose uses the Dockerfile if you add the build command to your project's docker-compose. yml. Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.

Is docker and Docker compose the same?

The key difference between docker run versus docker-compose is that docker run is entirely command line based, while docker-compose reads configuration data from a YAML file. The second major difference is that docker run can only start one container at a time, while docker-compose will configure and run multiple.

Does Docker compose override Dockerfile?

Docker-compose command doesn't override Dockerfile CMD.

What is the difference between Dockerfile and docker image?

A Dockerfile is a recipe for creating Docker images. A Docker image gets built by running a Docker command (which uses that Dockerfile ) A Docker container is a running instance of a Docker image.


2 Answers

Dockerfile

enter image description here

A Dockerfile is a simple text file that contains the commands a user could call to assemble an image.

Example, Dockerfile

FROM ubuntu:latest MAINTAINER john doe   RUN apt-get update RUN apt-get install -y python python-pip wget RUN pip install Flask  ADD hello.py /home/hello.py  WORKDIR /home 

Docker Compose

enter image description here

Docker Compose

  • is a tool for defining and running multi-container Docker applications.

  • define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.

  • get an app running in one command by just running docker-compose up

Example, docker-compose.yml

version: "3" services:   web:     build: .     ports:     - '5000:5000'     volumes:     - .:/code     - logvolume01:/var/log     links:     - redis   redis:     image: redis     volumes:       logvolume01: {} 
like image 193
code-8 Avatar answered Oct 02 '22 04:10

code-8


The answer is neither.

Docker Compose (herein referred to as compose) will use the Dockerfile if you add the build command to your project's docker-compose.yml.

Your Docker workflow should be to build a suitable Dockerfile for each image you wish to create, then use compose to assemble the images using the build command.

You can specify the path to your individual Dockerfiles using build /path/to/dockerfiles/blah where /path/to/dockerfiles/blah is where blah's Dockerfile lives.

like image 24
booyaa Avatar answered Oct 02 '22 05:10

booyaa