用 Docker 容器服务的方式搭建 nginx/php/mysql/redis/go/node/postgres/phpmyadmin 环境,易于维护、升级。
相关软件版本:
- PHP 7.1/7.2/7.3
- Golang 1.12
- MySQL 5.7
- Nginx 1.15
- Redis 3.2
- Node 11.12
- Postgres 10
PHP 扩展
- swoole v4.3.0
- Composer version 1.8.4
下载 zip 压缩包 && 解压
wget -c https://github.com/hopher/dockerfiles/archive/master.zip -O dockerfiles.zip
unzip dockerfiles.zip
mkdir -p ${HOME}/src
其中, ~/src
为 volumes 名称,可根据自己需要更改 docker-compose.yml
中 volumes 对应值
进入 docker-compose.yml 所在目录: 执行命令:
docker-compose up
如果没问题,下次启动时可以以守护模式启用,所有容器将后台运行:
docker-compose up -d
使用 docker-compose 基本上就这么简单,Docker 就跑起来了,用 stop,start 关闭开启容器服务。
更多的是在于编写 dockerfile 和 docker-compose.yml 文件。
可以这样关闭容器并删除服务:
docker-compose down
将项目源码放到 ~/src
目录下, 并运行
cd src
echo "<?php phpinfo();" > index.php
打开 url 访问 http://localhost/index.php
执行命令:
docker-compose --help
参数说明
-p
指定项目名称,默认为当前目录名, 也可以直接在docker-compose.yml
中设置image
,container_name
这2个属性
dockerfiles
|-- services # docker 相关服务
|-- docker-compose.yml # docker-compose.yml 定义
|-- deprecated.sh # 已弃用 shell 脚本, 勿使用
|-- mirrors # source.list 镜像源地址
~/src # 工作源码存放目录
# 删除所有容器
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"
系统代号 | 版本 |
---|---|
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
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.
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
@https://stackoverflow.com/questions/52819584/copying-local-git-config-into-docker-container @https://github.com/tomwillfixit/atomci/blob/master/docker-compose.yml
-
2019/04/14 添加 phpmyadmin (待完善...)
知识点: external_links / networks