What is Docker Compose?

Compose is a tool for defining and running complex applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.

Compose uses a YML\YAML file to configure application’s services. Then, with a single command, all the services can be started or stopped from the configuration. Some reasons you might want to use Compose :

  • Multiple isolated environments on a single host
  • Preserve volume data when containers are created
  • Only recreate containers that have changed
  • Variables and moving a composition between environments

Compose works in all environments: production, staging, development, testing as well as CI workflows.

Using Compose is basically a three-step process:

  • Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
  • Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
  • Run docker-compose up and Compose will start and run the entire app.

A docker-compose.yml looks like this:

version: '3'
services:
	web:
		build: .
		ports:
		- "5000:5000"
		volumes:
		- .:/code
		- logvolume01:/var/log
		links:
		- redis
	redis:
		image: redis
volumes:
	logvolume01: {}

Prerequisite

Docker Compose relies on Docker Engine. So make sure you have installed Docker Engine before installing Docker Composer. Instructions on installing Docker Engine can be found in the previous blog post: Install Docker on Ubuntu 18.04

Environment

  • Operating System : Ubuntu 18.04 LTS (64-bit)
  • Processor : Intel® Core™ i7-8750H CPU @ 2.20GHz × 12
  • Memory : 15.3 GiB

Download Latest Version of Docker Compose

Ensure that you have installed curl before running the following command.

sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Apply Executable Permissions to the Binary

sudo chmod +x /usr/local/bin/docker-compose

Test the Installation

docker-compose --version

It will output like below:

docker-compose version 1.25.4, build 8d51620a

Command line Completion for Docker and Docker Compose

Add docker and docker-compose to the plugins list in ~/.zshrc to run auto completion within the oh-my-zsh shell. In the following example, ... represent other Zsh plugins that have been installed earlier.

plugins=(... docker docker-compose
)

alt docker compose run

References

Advertisement

Cite This Work
APA Style
Shovon, A. R. (2020, March 10). Install Docker Compose on Ubuntu 18.04. Ahmedur Rahman Shovon. Retrieved March 29, 2024, from https://arshovon.com/blog/install-docker-compose-on-ubuntu-18-04/
MLA Style
Shovon, Ahmedur Rahman. “Install Docker Compose on Ubuntu 18.04.” Ahmedur Rahman Shovon, 10 Mar. 2020. Web. 29 Mar. 2024. https://arshovon.com/blog/install-docker-compose-on-ubuntu-18-04/.
BibTeX entry
@misc{ shovon_2020,
    author = "Shovon, Ahmedur Rahman",
    title = "Install Docker Compose on Ubuntu 18.04",
    year = "2020",
    url = "https://arshovon.com/blog/install-docker-compose-on-ubuntu-18-04/",
    note = "[Online; accessed 29-March-2024; URL: https://arshovon.com/blog/install-docker-compose-on-ubuntu-18-04/]"
}
Related Contents in this Website