Docker學習之docker-compose
docker-compose 安裝
1.Mac/Windows:
安裝docker的時候附帶安裝了。
2.Linux:
curl https://github.com/docker/compose
Linux 安裝docker-compose
curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s )-$(uname -m) > /usr/local/bin/docker-compose 直接將對應平臺的程序下載到本地輸出成為文件,#手動設置具體值,可到github查詢最新版本號 uname -s uname -m 查看系統版本信息 chmod a+x 目錄 :linux 所有人都可以執行這個文件,給權限的意識 最後, docker-compose --version 查看是否安裝成功 #### docker-compose實戰 ![](https://img2018.cnblogs.com/blog/1158417/201901/1158417-20190120154243988-827249705.png) 三層:nginx層、邏輯層、數據層 ![](https://img2018.cnblogs.com/blog/1158417/201901/1158417-20190120154347068-1853415769.png)
為應用創建一個目錄
mkdir ghost
cd ghost
為三個層分別創建目錄
mkdir ghost
mkdir nginx
mkdir data
cd ghost
touch Dockerfile
vi Dockerfile
內容:
FROM ghost
COPY ./config.js /var/lib/ghost/config.js
EXPOSE 2368
CMD ["npm","start","--production"]
cp ../../backup/ghost/ghost/config.js
#### 同樣的,構建nginx
cd ..
touch Dockerfile
vi Dockerfile
內容:
FROM nginx
COPY nginx.conf /etc/niginx/nginx.conf
EXPOSE 80
touch nginx.conf
vi nginx.conf
內容:
woker_processes 4;
events {woker_connections 1024}
http {
server {
listen 80;
location / {
proxy_pass http://ghost-app:2368;
}
}
}
#### 創建docker-compose.yml
在ghost路徑下
touch docker-compose.yml
內容:
version: ‘2‘
networks:
ghost:
services:
ghost-app:
build: ghost
networks:
- ghost
depends_on:
- db
ports:
- "2368:2368"
nginx:
build: nginx
networks:
- ghost
depends_on:
- ghost-app
ports:
- "80:80"
db:
image: "mysql :5.7.15"
networks:
- ghost
enviroment:
MYSQL_ROOT_PASSWORD: mysqlroot
MYSQL_USER: ghost
MSYQL_PASSWORD: ghost
volumes:
- $PWD/data:/var/lib/mysql
ports:
- "3306:3306"
![](https://img2018.cnblogs.com/blog/1158417/201901/1158417-20190120161816447-798945050.png)
#### 讓docker-compose 拉起來
第一次生產鏡像
docker-compose up -d
停止
docker-compose stop
幹掉停止的
docker-compose rm
在已存在鏡像的情況下,重新build
docker-compose build
然後
docker-compose up -d
成功啟動一個多容器app
訪問:localhost:80
訪問:localhost:80/ghost
```
docker-compose 常用命令
Docker學習之docker-compose