Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Latest commit

 

History

History
70 lines (47 loc) · 1.58 KB

13_compose.md

File metadata and controls

70 lines (47 loc) · 1.58 KB

Docker Lab: Orchestration

Instead of managing the containers with the docker command, you may use Docker Compose to handle them.

First if on Ubuntu install the docker-compose command:

sudo apt-get install docker-compose

Note: On Windows the Docker installer usually includes docker-compose already.

Docker Compose file

Previously we run:

docker run --name mariadb-container-with-existing-external-volume -v$(pwd)/datastore-mysql:/var/lib/mysql -it -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb

and

docker run -itd --name php-app -p8080:80 --link mariadb-container-with-existing-external-volume php-app

We now create a file called docker-compose.yml:

version: '2'

services:

  php-app:
    image: php-app
    ports:
      - '8080:80'
    networks:
      - docker-techlab

  mariadb-container-with-existing-external-volume:
    image: mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=my-secret-pw

    volumes:
      - 'volume-mariadb:/var/lib/mysql'

    networks:
      - docker-techlab

networks:
  docker-techlab:

volumes:
  volume-mariadb:

For each of the docker run commands, you add an entry under services, containing the appropriate options. The various options are described in the Compose file reference.

Having this file, you can run both containers with a simple command:

docker-compose up

Then again, check localhost/db.php in the browser.

← Troubleshooting | Registry and Docker Hub →