Dockerfiles
用 Docker 容器服务的方式搭建 nginx/php/mysql/redis/go/node/postgres/phpmyadmin 环境,易于维护、升级。
镜像版本
公用存储: (网段名: dockerfiles_default)
- MySQL 5.7
- Redis 3.2
- Postgres 10
其它:
- PHP 7.1/7.2/7.3
- 扩展: swoole v4.3.0
- 扩展: Composer version 1.8.4
- Golang 1.12
- Nginx 1.15
- Node 11.12
- tomcat 8-jre8
构建自定义项目组合, 配置说明
公用存储(MySQL, Redis, Postgres), 使用了网段: dockerfiles_default
你可以通过复制 && 修改 .env.example 来自定义构建项目组合
示例:
cp .env.example .env
vi .env
使用
1. 下载
下载 zip 压缩包 && 解压
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 对应值
2. docker-compose 构建项目
进入 docker-compose.yml 所在目录: 执行命令:
cp .env.example .env
docker-compose up
如果没问题,下次启动时可以以守护模式启用,所有容器将后台运行:
docker-compose up -d
使用 docker-compose 基本上就这么简单,Docker 就跑起来了,用 stop,start 关闭开启容器服务。
更多的是在于编写 dockerfile 和 docker-compose.yml 文件。
可以这样关闭容器并删除服务:
docker-compose down
3. 测试
将项目源码放到 ~/app 目录下, 并运行
cd src
echo "<?php phpinfo();" > index.php
打开 url 访问 http://localhost/index.php
4. 常用指令
-
帮助
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
5. 目录结构
dockerfiles
|-- services # docker 相关服务
|-- docker-compose.yml # 通用配置文件
|-- docker-compose-tomcat.yml # tomcat 配置文件
|-- mirrors # source.list 镜像源地址
~/app # 工作源码存放目录
Version 3 (docker-composer) 不再支持参数说明
depends_on
笔者解读: 通过配置
networks参数更好地改进
depends_ondoes not wait fordbandredisto be “ready” before startingweb- 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.- Version 3 no longer supports the
conditionform ofdepends_on. - The
depends_onoption 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.
各系统软件源
Ubuntu
| 系统代号 | 版本 |
|---|---|
| precise | 12.04 |
| trusty | 14.04 |
| vivid | 15.04 |
| xenial | 16.04 |
| zesty | 17.04 |
Debian
| 系统代号 | 版本 |
|---|---|
| squeeze | 6.x |
| wheezy | 7.x |
| jessie | 8.x |
| stretch | 9.x |
| buster | 10.x |
NOTE:
查询自己的Linux版本cat /etc/issue
git ssh 密钥配置
For your host machine which run git, all the contents of git config --list is stored in files:
- If use
git config --systemto configure them, they are stored in/etc/gitconfig - If use
git config --globalto 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
版本计划
- [] 增加 .env 配置镜相版本
反馈、参与贡献
点击 - 提交你的意见, 十分感谢
一起组队, 参与贡献
先 fork 一份, 按照格式:
services/名称/版本号/Dockerfile
示例:
services/php/v7.1/Dockerfile
在 services/php/v7.1 文件夹中,编写具体内容,然后 Pull Request
贡献名单
... 期待你的留名 ...