用 Docker 容器服務的方式搭建 nginx/php/mysql/redis/go/node/postgres/phpmyadmin 環境,易於維護、升級。php
鏡像版本html
公用存儲: (網段名: dockerfiles_default)java
其它:node
公用存儲(MySQL, Redis, Postgres), 使用了網段: dockerfiles_defaultmysql
你能夠經過複製 && 修改 .env.example 來自定義構建項目組合nginx
示例:git
cp .env.example .env
vi .env
複製代碼
下載 zip 壓縮包 && 解壓github
wget -c https://github.com/hopher/dockerfiles/archive/master.zip -O dockerfiles.zip
unzip dockerfiles.zip
mkdir -p ${HOME}/app
複製代碼
其中, ~/app
爲 volumes 名稱,可根據本身須要更改 docker-compose.yml
中 volumes 對應值web
進入 docker-compose.yml 所在目錄: 執行命令:redis
cp .env.example .env
docker-compose up
複製代碼
若是沒問題,下次啓動時能夠以守護模式啓用,全部容器將後臺運行:
docker-compose up -d
複製代碼
使用 docker-compose 基本上就這麼簡單,Docker 就跑起來了,用 stop,start 關閉開啓容器服務。
更多的是在於編寫 dockerfile 和 docker-compose.yml 文件。
能夠這樣關閉容器並刪除服務:
docker-compose down
複製代碼
將項目源碼放到 ~/app
目錄下, 並運行
cd src
echo "<?php phpinfo();" > index.php
複製代碼
打開 url 訪問 http://localhost/index.php
幫助
docker-compose --help
複製代碼
列出網絡 (包括跨羣集中多個主機的網絡)
docker network ls
複製代碼
運行時,指定配置文件
docker-compose -p java -f docker-compose-tomcat.yml up -d
複製代碼
參數:
-p
工程名稱, 這裏爲 java, 表明java 相關配置-f
配置文件-d
後臺運行經常使用shell
組合
# 刪除全部容器
docker stop `docker ps -q -a` | xargs docker rm
# 刪除全部標籤爲none的鏡像
docker images|grep \<none\>|awk '{print $3}'|xargs docker rmi
# 查找容器IP地址
docker inspect 容器名或ID | grep "IPAddress"
# 建立網段, 名稱: mynet, 分配兩個容器在同一網段中 (這樣子才能夠互相通訊)
docker network create mynet
docker run -d --net mynet --name container1 my_image
docker run -it --net mynet --name container1 another_image
複製代碼
更多幫助信息
docker-compose -h|--help
dockerfiles
|-- services # docker 相關服務
|-- docker-compose.yml # 通用配置文件
|-- docker-compose-tomcat.yml # tomcat 配置文件
|-- mirrors # source.list 鏡像源地址
~/app # 工做源碼存放目錄
複製代碼
depends_on
筆者解讀: 經過配置
networks
參數更好地改進
depends_on
does not wait for db
and redis
to be 「ready」 before starting web
- only until they have been started. If you need to wait for a service to be ready, see Controlling startup order for more on this problem and strategies for solving it.condition
form of depends_on
.depends_on
option is ignored when deploying a stack in swarm mode with a version 3 Compose file.links
Warning: The --link
flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link
. One feature that user-defined networks do not support that you can do with --link
is sharing environmental variables between containers. However, you can use other mechanisms such as volumes to share environment variables between containers in a more controlled way.
系統代號 | 版本 |
---|---|
precise | 12.04 |
trusty | 14.04 |
vivid | 15.04 |
xenial | 16.04 |
zesty | 17.04 |
系統代號 | 版本 |
---|---|
squeeze | 6.x |
wheezy | 7.x |
jessie | 8.x |
stretch | 9.x |
buster | 10.x |
NOTE:
查詢本身的Linux版本cat /etc/issue
For your host machine which run git, all the contents of git config --list
is stored in files:
git config --system
to configure them, they are stored in /etc/gitconfig
git config --global
to configure them, they are stored in ~/.gitconfig
示例:
volumes:
# Git and ssh config
- ~/.ssh:/root/.ssh:ro # Change - ssh key needed to push to github
- ~/.gitconfig:/root/.gitconfig:ro # Change - git config needed for user details
#- /tmp/ssh_auth_sock:/tmp/ssh_auth_sock #Static - needed to push to github without prompt
複製代碼
點擊 - 提交你的意見, 十分感謝
一塊兒組隊, 參與貢獻
先 fork
一份, 按照格式:
services/名稱/版本號/Dockerfile
示例:
services/php/v7.1/Dockerfile
複製代碼
在 services/php/v7.1 文件夾中,編寫具體內容,而後 Pull Request
... 期待你的留名 ...