mysql中composekey定义,docker-compose 自定义 nginx/php/mysql/redis/go/java/tomcat 组合环境

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 \|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_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.

Version 3 no longer supports the condition form of depends_on.

The 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.

各系统软件源

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 --system to configure them, they are stored in /etc/gitconfig

If use 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

复制代码

版本计划

[] 增加 .env 配置镜相版本

反馈、参与贡献

一起组队, 参与贡献

先 fork 一份, 按照格式:

services/名称/版本号/Dockerfile

示例:

services/php/v7.1/Dockerfile

复制代码

在 services/php/v7.1 文件夹中,编写具体内容,然后 Pull Request

贡献名单

... 期待你的留名 ...

参考资料

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值