docker file 基本指令
|
准备
创建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