docker file

docker file 基本指令

 
 

指令

描述

FROM

构建新镜像是基于哪个镜像

MAINTAINER

镜像维护者姓名或邮箱地址

RUN

构建镜像时运行的Shell命令

COPY

拷贝文件或目录到镜像中

ENV

设置环境变量

USER

为RUN、CMD和ENTRYPOINT执行命令指定运行用户

EXPOSE

声明容器运行的服务端口

HEALTHCHECK

容器中服务健康检查

WORKDIR

为RUN、CMD、ENTRYPOINT、COPY和ADD设置工作目录

ENTRYPOINT

运行容器时执行,如果有多个ENTRYPOINT指令,最后一个生效

CMD

运行容器时执行,如果有多个CMD指令,最后一个生效

准备

创建volume并查看(其实run的时候)

root@bogon: ~/dockerfile 00:07:40
$ docker volume create mysql_vol
root@bogon: ~/dockerfile 00:07:40
$ docker volume create wwwroot
$ docker volume ls
DRIVER              VOLUME NAME
local               mysql-vol
local               wwwroot
root@bogon: ~/dockerfile 00:08:21
$ 

创建自定义网络lnmp

root@bogon: ~/dockerfile 00:14:05
$ docker network create lnmp
$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
a8f190100335        bridge              bridge              local
1ff2dd488eff        host                host                local
3bc39c071277        lnmp                bridge              local
1c8102042db6        none                null                local
2c8ded728719        test                bridge              local
root@bogon: ~/dockerfile 00:14:57
$ 

 

NGINX的dockerfile

FROM centos:7
MAINTAINER www.ctnrs.com
RUN yum install -y gcc gcc-c++ make \
    openssl-devel pcre-devel gd-devel \
    iproute net-tools telnet wget curl && \
    yum clean all && \
    rm -rf /var/cache/yum/*
    
COPY nginx-1.15.5.tar.gz /
#RUN wget http://nginx.org/download/nginx-1.15.5.tar.gz && \
RUN tar zxf nginx-1.15.5.tar.gz && \
    cd nginx-1.15.5 && \
    ./configure --prefix=/usr/local/nginx \
    --with-http_ssl_module \
    --with-http_stub_status_module && \
    make -j 4 && make install && \
    rm -rf /usr/local/nginx/html/* && \
    echo "ok" >> /usr/local/nginx/html/status.html && \
    cd / && rm -rf nginx-1.12.2* && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/nginx/sbin
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
WORKDIR /usr/local/nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

php的dockerfile

FROM centos:7
MAINTAINER www.ctnrs.com
RUN yum install epel-release -y && \
    yum install -y gcc gcc-c++ make gd-devel libxml2-devel \
    libcurl-devel libjpeg-devel libpng-devel openssl-devel \
    libmcrypt-devel libxslt-devel libtidy-devel autoconf \
    iproute net-tools telnet wget curl && \
    yum clean all && \
    rm -rf /var/cache/yum/*

#RUN wget http://docs.php.net/distributions/php-5.6.36.tar.gz && \
COPY php-5.6.36.tar.gz /
RUN tar zxf php-5.6.36.tar.gz && \
    cd php-5.6.36 && \
    ./configure --prefix=/usr/local/php \
    --with-config-file-path=/usr/local/php/etc \
    --enable-fpm --enable-opcache \
    --with-mysql --with-mysqli --with-pdo-mysql \
    --with-openssl --with-zlib --with-curl --with-gd \
    --with-jpeg-dir --with-png-dir --with-freetype-dir \
    --enable-mbstring --with-mcrypt --enable-hash && \
    make -j 4 && make install && \
    cp php.ini-production /usr/local/php/etc/php.ini && \
    cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf && \
    sed -i "90a \daemonize = no" /usr/local/php/etc/php-fpm.conf && \
    mkdir /usr/local/php/log && \
    cd / && rm -rf php* && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/php/sbin
COPY php.ini /usr/local/php/etc/
COPY php-fpm.conf /usr/local/php/etc/
WORKDIR /usr/local/php
EXPOSE 9000
CMD ["php-fpm"]

nginx run

docker run -itd --name lnmp_nginx  -p 88:80 --net=lnmp --mount src=wwwroot,dst=/wwwroot nginx:v1

php run

docker  run -itd --name lnmp_php --net=lnmp --mount src=wwwroot,dst=/wwwroot php:v1

mysql run

docker run -itd --name lnmp_mysql --net=lnmp -v mysql-vol:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress mysql:5.7 --character-set-server=utf8

查看volume模式下wwwroot卷位置

root@bogon: ~/dockerfile 00:17:14
$ docker volume inspect wwwroot
[
    {
        "CreatedAt": "2019-03-14T23:43:08+08:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/wwwroot/_data",
        "Name": "wwwroot",
        "Options": null,
        "Scope": "local"
    }
]
root@bogon: ~/dockerfile 00:17:21
$ 

测试

root@bogon: /var/lib/docker/volumes/wwwroot/_data 00:18:22
$ cat index.html 
hello
root@bogon: /var/lib/docker/volumes/wwwroot/_data 00:18:44
$ cat test.php 
<?php phpinfo();?>

curl

root@bogon: /var/lib/docker/volumes/wwwroot/_data 00:21:15
$ curl 192.168.1.199:88
hello
root@bogon: /var/lib/docker/volumes/wwwroot/_data 00:21:25
$ 
root@bogon: /var/lib/docker/volumes/wwwroot/_data 00:21:25
$ curl 192.168.1.199:88/test.php

安装wordpress

cd /var/lib/docker/volumes/wwwroot/_data
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
tar zxvf wordpress-4.9.4-zh_CN.tar.gz

访问 ip+prot+wordpress

转载于:https://www.cnblogs.com/Carr/p/10537851.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值