How to install and create applications with Docker Compose

Requirements

Installing docker compose on Ubuntu 18.04

Step 1 : To download and install the Docker Compose, run the following commands. again checking that you are running the latest version by visiting the releases page at https://github.com/docker/compose/releases/

COMPOSEVERSION=1.25.1-rc1
curl -L https://github.com/docker/compose/releases/download/$COMPOSEVERSION/docker-compose-`uname -s`-`uname -m` >/tmp/docker-compose
chmod +x /tmp/docker-compose
sudo mv /tmp/docker-compose /usr/local/bin/docker-compose

Step 2 : Once it’s installed, you should be able to run the following two commands confirm the versions of the software is correctly:

docker-compose version

Creating first Docker Compose application

Step 1 : Create a directory for the application

mkdir wordpress_compose
cd wordpress_compose/

Step 2 :  Next, create docker-compose.yml to define the app.

nano docker-compose.yml

version: '3.1'
services:
    wordpress:
    image: wordpress
    restart: always
    ports:
        - 8080:80
    environment:
        WORDPRESS_DB_PASSWORD: example
    mysql:
    image: mysql:5.7
    restart: always
    environment:
        MYSQL_ROOT_PASSWORD: example

We took the preceding example from the official WordPress Docker repository on Docker Hub (https://registry.hub.docker.com/_/wordpress/).

Step 3 : Within the app directory, run the following command to build and start the app

docker-compose up

Step 3 : Docker Compose downloads both MySQL and WordPress images, if not available locally from the official Docker Registry. First, it starts the db container from the MySQL image; then, it starts the WordPress container

Step 4 : Once the build is complete, access the WordPress installation page from http://localhost:8080 or http://<host-ip>:8080.

Add Comment