---
# System prepended metadata

title: docker-compose
tags: [docker]

---

# docker-compose

###### tags: `docker`

## 使用python安裝
### 安裝python需要Homebrew

網址：https://brew.sh
	
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

### 安裝python
	brew install python 
### 安裝docker-compose
	pip3 install docker-compose
注意python版本3需要使用pip3

#### 指令
	docker-compose up -d
啟用與更新所有容器(若之後有新增或修改只會,重新建置修改項目)
	
    docker-cxompose down
停用所有容器

## 使用方法
1.先建立統一管理的專案資料夾,資料夾中新增一個docker-compose.yml

###### Ex:
![](https://i.imgur.com/pKb0Y6p.png)


2.設定yml檔(斷行要明確否則會有錯誤)

    version: "3"

    networks:
      new-net:
        driver: bridge
        external: true

    services:
      lohasglasses:
        image:  ubuntu:laravel
        container_name: lohasglasses
        restart: unless-stopped
        working_dir: /var/www/html
        command: >
          bash -c "apachectl -D FOREGROUND"
        volumes:
          - $PWD/lohasglasses_php:/var/www/html
        networks:
          - new-net
        ports:
          - "8001:80"


      lohastracking:
        image:  ubuntu:laravel
        container_name: lohastracking
        restart: unless-stopped
        command: >
          bash -c "apachectl -D FOREGROUND"
        volumes:
          - $PWD/lohastracking_php:/var/www/html
        networks:
          - new-net
        ports:
          - "8002:80"

      incinerationxindian:
        image:  ubuntu:laravel
        container_name: incinerationxindian
        restart: unless-stopped
        command: >
          bash -c "apachectl -D FOREGROUND"
        volumes:
          - $PWD/incinerationxindian_php:/var/www/html
        networks:
          - new-net
        ports:
          - "8003:80"

      incinerationshulin:
        image:  ubuntu:laravel
        container_name: incinerationshulin
        restart: unless-stopped
        command: >
          bash -c "apachectl -D FOREGROUND"
        volumes:
          - $PWD/incinerationshulin_php:/var/www/html
        networks:
          - new-net
        ports:
          - "8004:80"

      YunTechCSR:
        image:  ubuntu:laravel
        container_name: YunTechCSR
        restart: unless-stopped
        command: >
          bash -c "apachectl -D FOREGROUND"
        volumes:
          - $PWD/YunTechCSR:/var/www/html
        networks:
          - new-net
        ports:
          - "8005:80"

      usecwebsite:
        image:  ubuntu:laravel
        container_name: usecwebsite
        restart: unless-stopped
        command: >
          bash -c "apachectl -D FOREGROUND"
        volumes:
          - $PWD/usecwebsite_php:/var/www/html
        networks:
          - new-net
        ports:
          - "8006:80"
      
      baliplant:
        image:  ubuntu:laravel9
        container_name: baliplant
        restart: unless-stopped
        command: >
          bash -c "apachectl -D FOREGROUND"
        volumes:
          - $PWD/baliplant:/var/www/html
        networks:
          - new-net
        ports:
          - "8007:80"
          
## 說明
###### docker版本號
	version 
###### 橋接器若不需要可以不加(若有需要可參考docker networks筆記)
	networks
###### new-net橋接器名稱
    new-net:
###### driver網路類型
	driver: bridge
###### external橋接網路是否對外
	external: true
(所有容器可以共用同一個Mysql容器,可依照容器名稱互相連接)
#### services容器設定
	lohasglasses: 
        image:  ubuntu:laravel //image名稱
        container_name: lohasglasses //容器名稱
        restart: unless-stopped
        command: >
          bash -c "apachectl -D FOREGROUND" //docker start後執行
        volumes:
          - $PWD/lohasglasses_php:/var/www/html //鏡像位置
        networks:
          - new-net //橋接器可不加
        ports:
          - "8001:80" //對內對外port
          
## 完成結果


![](https://i.imgur.com/IPChNhB.png)



![](https://i.imgur.com/i2Lq9G5.png)
