用 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
... 期待你的留名 ...