Skip to content

Instantly share code, notes, and snippets.

@dunderrrrrr
Created February 21, 2020 13:42
Show Gist options
  • Save dunderrrrrr/c18aa27c7529d698420197c49a3a0a72 to your computer and use it in GitHub Desktop.
Save dunderrrrrr/c18aa27c7529d698420197c49a3a0a72 to your computer and use it in GitHub Desktop.
Compose is a tool for defining and running multi-container Docker applications.

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating-system kernel and are thus more lightweight than virtual machines.

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. To learn more about all the features of Compose, see the list of features.

Install docker-compose

APT

$ sudo apt install docker-compose

Curl

docs.docker.com/compose/install

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

Test installation

$ docker-compose --version

Example

Let's say you have two containers you would like to deploy. You have two custom commands, these two for example.

Container 1, memcached

$ docker run --name memcached_yopass -d memcached

Container 2, yopass (yopass is real nice btw, thanks @jhaals)

$ docker run -p 1337:1337 --link memcached_yopass:memcache -d jhaals/yopass --memcached=memcache:11211

To deploy both containers in a compose, create docker-compose.yml and win.

version: '2.0'
services:
  memcached:
    restart: always
    image: "memcached"
    ports:
      - "11211:11211"
  yopass:
    restart: always
    image: "jhaals/yopass"
    ports:
      - "1337:1337"
    command: "--memcached=memcached:11211"

To deploy compose-file, run

$ docker-compose up -d

It's that easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment