cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

middleware:container:docker:docker-compose



docker-compose

Reference

Command

docker-compose up -d start docker-compose Execute in the directory where docker-compose.yml is located
docker-compose down stop docker-compose
docker-compose ps Container list
docker-compose exec CONTAINER /bin/bash Enter a running container
docker-compose kill Forcibly stop all containers
docker-compose rm Delete all containers


Install

# pip install docker-compose

or

# curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
# docker-compose --version


Uninstall

pip uninstall docker-compose

or

rm /usr/local/bin/docker-compose


Example1

Docker Registry


MyApp

./app
./app/counter.php
./mysql
./mysql/init
./mysql/init/init.sql
./mysql/data
./htdocs
./docker-compose.yml
./build
./build/phpapp
./build/phpapp/Dockerfile



docker-compose.yml

version: "2"
services:
  mysql:
    image: mysql:5.7
    ports:
      - "3306:3306"
    volumes:
      - "./mysql/init:/docker-entrypoint-initdb.d"
      - "./mysql/data:/var/lib/mysql"
    environment:
      - MYSQL_ROOT_PASSWORD=secret
  phpapp:
    image: phpapp
    build: ./build/phpapp
    volumes:
      - "./app:/var/www/html"
    ports:
      - "8080:80"

https://qiita.com/hiyuzawa/items/81490020568417d85e86


Example2(Apache + PHP + Mysql)

Directory structure

docker-compose.yml

html/
     inex.php

php/
    Dockerfile
    php.ini
    apache2.conf

Mysql/
     Dockerfile
     my.cnf

data/   #For MySQL Data
docker-compose.yml
version: '3.8'

services:

  # PHP Apache
  php-apache:
    build: ./php
    ports:
      - "8080:80"
    volumes:
      - ./html:/var/www/html
    restart: always
    depends_on:
      - mysql

  # MySQL
  mysql:
    build: ./mysql
    ports:
      - 3306:3306
    volumes:
      - ./mysql/initdb.d:/docker-entrypoint-initdb.d
      - ./data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: sample_root_passward
      MYSQL_DATABASE: sample_db
      MYSQL_USER: sample_user
      MYSQL_PASSWORD: sample_pass
php/Dockerfile
FROM php:5.4-apache

# Set php.ini
COPY ./php.ini /usr/local/etc/php/

# Set apache conf (Before tag:5.4-apache)
COPY ./apache2.conf /etc/apache2/
COPY ./sites/*.conf /etc/apache2/sites-available/

# Install MySQL connection module
RUN apt-get update \
  && apt-get install -y libpq-dev \
  && docker-php-ext-install pdo_mysql pdo_pgsql mysqli mbstring


docker-compse operation

$ docker-compose build --no-cache
$ docker-compose up -d

$ docker-compose ps
$ docker container ls
$ docker exec -it eaae0xxxxxxx /bin/bash
## Stop the container 
$ docker-compose stop

## Stop the container and delete the container and network 
$ docker-compose down

## Stop the container, delete the container and network, and delete the image 
$ docker-compose down --rmi all --volumes



middleware/container/docker/docker-compose.txt ยท Last modified: 2021/08/17 by admin

Page Tools