k8s php mysql nginx,基于docker 搭建 nginx+php+mysql+redis 的环境,可根据需求切换php版本...

1,目录结构

d4cb928f67904bab58d007bc39fe339b.png

2,dockerfile文件创建,以nginx为例【命令集,从无到有的构建镜像】

FROMcentos:latest ------基于centos系统镜像MAINTAINER weeds ENV TZ "Asia/Shanghai"# 安装依赖RUNyum -y update && \ ——— RUN命令是Dockerfile执行命令的核心部分。它接受命令作为参数并用于创建镜像

yum install -y gcc automake autoconf libtool make gcc-c++ vixie-cron wget zlib file openssl-devel sharutils zip bash vim cyrus-sasl-devel libmemcached libmemcached-devel libyaml libyaml-devel unzip libvpx-devel openssl-devel ImageMagick-devel autoconf tar gcc libxml2-devel gd-devel libmcrypt-devel libmcrypt mcrypt mhash libmcrypt libmcrypt-devel libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel bison libtool-ltdl-devel net-tools && \

yum clean all

# 安装 nginxRUNcd /tmp && \

wget http://nginx.org/download/nginx-1.14.0.tar.gz && \

tar xzf nginx-1.14.0.tar.gz && \

cd /tmp/nginx-1.14.0&& \

./configure \

--prefix=/usr/local/nginx \

--with-http_ssl_module --with-http_sub_module --with-http_dav_module --with-http_flv_module \

--with-http_gzip_static_module --with-http_stub_status_module --with-debug && \

make && \

make installEXPOSE 80 443---- 对外开放端口

#启动nginxCMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;”] ----和RUN命令相似,CMD可以用于执行特定的命令。和RUN不同的是,这些命令不是在镜像构建的过程中执行的,而是在用镜像构建容器后被调用

3,docker-compose.yml 文件 以nginx为例 【compose 文件是一个定义服务、 网络和卷的 YAML 文件 。Compose 文件的默认路径是 ./docker-compose.yml】

version : ‘2.1’ ——版本

services : ---服务

nginx : ---名称

build :

context : ./nginx ---指定Dockerfile 的文件路径

dockerfile : dockerfile ----使用此 dockerfile 文件来构建,必须指定构建路径

ports : ——映射端口

-"${NGINX_HOST_HTTP_PORT}:80” — 读取.env 文件的NGINX_HOST_HTTP_PORT值,把docker的80端口映射到主机的.env配置端口

- "${NGINX_HOST_HTTPS_PORT}:443"volumes : —--------挂载目录 主机目录:docker容器目录

- ./nginx/logs:/usr/local/nginx/logs

- ${WORKPLACE}:/usr/local/nginx/html

- ./nginx/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf:ro

- ./nginx/conf/vhost:/usr/local/nginx/conf/vhost:ro

container_name : nginx ------容器名称

external_links : -----链接到外部容器

- php

restart : always ——随docker启动而启用 no

php :

build :

context : ./php

dockerfile : dockerfile

args:

- WEEDS_PHP_VERSION=${PHP_VERSION}

ports :

-"9000:9000"volumes :

- ${WORKPLACE}:/usr/local/nginx/html

- ./php/conf/php${PHP_VERSION}.ini:/usr/local/php/lib/php.ini:ro

container_name : php

external_links :

- mysql

restart : always

4, .env配置

### NGINX #################################################

NGINX_HOST_HTTP_PORT=80NGINX_HOST_HTTPS_PORT=443

5,启动目录

sudo docker-compose up -d nginx

6,成功后

docker ps查看运行中的容器

dockerps -a 查看运行中的容器,包括未运行的

docker images 列出本地镜像

dockerkill「容器id」 杀掉一个运行中的容器或者多个,空格隔开

dockerrm「容器id」 删除一个或多少容器

dokcer rmi 「镜像id」 删除镜像,释放空间

docker-compose restart/start/stop 「容器名称」 重启/启动/停止

7,其他

GitHub地址:https://github.com/weedsks/docker

docker官网:https://docs.docker.com/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值