huangyt39 / dockerfiles

nginx/php/mysql/redis/go 环境搭建

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dockerfiles

用 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

使用

1.下载

下载 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 对应值

2.docker-compose 构建项目

进入 docker-compose.yml 所在目录: 执行命令:

docker-compose up

如果没问题,下次启动时可以以守护模式启用,所有容器将后台运行:

docker-compose up -d

使用 docker-compose 基本上就这么简单,Docker 就跑起来了,用 stop,start 关闭开启容器服务。
更多的是在于编写 dockerfile 和 docker-compose.yml 文件。

可以这样关闭容器并删除服务:

docker-compose down

3. 测试

将项目源码放到 ~/src 目录下, 并运行

cd src
echo "<?php phpinfo();" > index.php

打开 url 访问 http://localhost/index.php

4.帮助

执行命令:

docker-compose --help

参数说明

  • -p 指定项目名称,默认为当前目录名, 也可以直接在docker-compose.yml中设置image, container_name 这2个属性

5.目录结构

dockerfiles
    |-- services            # docker 相关服务
    |-- docker-compose.yml  # docker-compose.yml 定义
    |-- deprecated.sh       # 已弃用 shell 脚本, 勿使用
    |-- mirrors             # source.list 镜像源地址
~/src                       # 工作源码存放目录

常用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"

各系统软件源

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

番外篇

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.

@https://docs.docker.com/compose/compose-file/

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

@https://stackoverflow.com/questions/52819584/copying-local-git-config-into-docker-container @https://github.com/tomwillfixit/atomci/blob/master/docker-compose.yml

更新记录

参考资料

About

nginx/php/mysql/redis/go 环境搭建


Languages

Language:Dockerfile 69.3%Language:Shell 30.7%