您好,登錄后才能下訂單哦!
1.Dockerfile格式
2. Dockerfile指令
3. Build鏡像
4. 構建Nginx,PHP,Tomcat基礎鏡像
?? 前提:上傳文件dockerfile .zip和wordpress-4.9.4-zh_CN.tar.gz
[root@localhost?first_stage]#?unzip?dockerfile\?.zip?-d?Dockerfile/ Archive:??dockerfile?.zip ??inflating:?Dockerfile/Dockerfile-nginx?? ??inflating:?Dockerfile/Dockerfile-php?? ??inflating:?Dockerfile/Dockerfile-tomcat?? ??inflating:?Dockerfile/nginx.conf??? ??inflating:?Dockerfile/php-fpm.conf?? ??inflating:?Dockerfile/php.ini
構建Nginx基礎鏡像:
[root@localhost?first_stage]#?sed?-i?'s/1.12.2/1.15.5/g'?Dockerfile-nginx [root@localhost?first_stage]#?cat?Dockerfile-nginx FROM?centos:7 MAINTAINER?www.dengaosky.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/* RUN?wget?http://nginx.org/download/nginx-1.15.5.tar.gz?&&?\ ????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.15.5*?&&?\ ????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;"] [root@localhost?first_stage]#?docker?build?-t??nginx:v1?-f?Dockerfile-nginx?. [root@localhost?first_stage]#?docker?images REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????SIZE nginx???????????????v1??????????????????d25e10f6dc2f????????3?minutes?ago???????369MB centos??????????????7???????????????????9f38484d220f????????4?months?ago????????202MB [root@localhost?first_stage]#
構建PHP基礎鏡像:
[root@localhost?first_stage]#?cat?Dockerfile-php? FROM?centos:7 MAINTAINER?www.dengaosky.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?&&?\ ????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"] [root@localhost?first_stage]#?docker?build?-t??php:v1?-f?Dockerfile-php?. [root@localhost?first_stage]#?docker?images REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????SIZE php?????????????????v1??????????????????402fe17abd8f????????4?seconds?ago???????522MB nginx???????????????v1??????????????????d25e10f6dc2f????????15?minutes?ago??????369MB centos??????????????7???????????????????9f38484d220f????????4?months?ago????????202MB [root@localhost?first_stage]#
構建Tomcat基礎鏡像:
[root@localhost?first_stage]#?sed?-i?"s/8.0.52/8.0.46/g"?Dockerfile-tomcat? [root@localhost?first_stage]#?cat?Dockerfile-tomcat? FROM?centos:7 MAINTAINER?www.dengaosky.com ENV?VERSION=8.0.46 RUN?yum?install?java-1.8.0-openjdk?wget?curl?unzip?iproute?net-tools?-y?&&?\ ????yum?clean?all?&&?\ ????rm?-rf?/var/cache/yum/* #RUN?wget?http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz?&&?\ RUN?wget?http://archive.apache.org/dist/tomcat/tomcat-8/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz?&&?\ ????tar?zxf?apache-tomcat-${VERSION}.tar.gz?&&?\ ????mv?apache-tomcat-${VERSION}?/usr/local/tomcat?&&?\ ????rm?-rf?apache-tomcat-${VERSION}.tar.gz?/usr/local/tomcat/webapps/*?&&?\ ????mkdir?/usr/local/tomcat/webapps/test?&&?\ ????echo?"ok"?>?/usr/local/tomcat/webapps/test/status.html?&&?\ ????sed?-i?'1a?JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom"'?/usr/local/tomcat/bin/catalina.sh?&&?\ ????ln?-sf?/usr/share/zoneinfo/Asia/Shanghai?/etc/localtime ENV?PATH?$PATH:/usr/local/tomcat/bin WORKDIR?/usr/local/tomcat EXPOSE?8080 CMD?["catalina.sh",?"run"] [root@localhost?first_stage]#?docker?build?-t??tomcat:v1?-f?Dockerfile-tomcat?. [root@localhost?first_stage]#?docker?images REPOSITORY??????????TAG?????????????????IMAGE?ID????????????CREATED?????????????SIZE tomcat??????????????v1??????????????????118b74bae95f????????52?seconds?ago??????427MB php?????????????????v1??????????????????402fe17abd8f????????55?minutes?ago??????522MB nginx???????????????v1??????????????????d25e10f6dc2f????????About?an?hour?ago???369MB centos??????????????7???????????????????9f38484d220f????????4?months?ago????????202MB [root@localhost?first_stage]#
5. 快速搭建LNMP網站平臺
快速部署LNMP網站平臺 1、自定義網絡? docker?network?create?lnmp 2、創建Mysql容器? docker?run?-d?\ ?--name?lnmp_mysql?\ ?--net?lnmp?\ ?--mount?src=mysql-vol,dst=/var/lib/mysql?\ ?-e?MYSQL_ROOT_PASSWORD=123456?-e?MYSQL_DATABASE=wordpress?mysql:5.7??--character-set-server=utf8? 3、創建PHP容器? docker?run?-d?--name?lnmp_php?--net?lnmp?--mount?src=wwwroot,dst=/wwwroot?php:v1? 4、創建Nginx容器? docker?run?-d?--name?lnmp_nginx?--net?lnmp?-p?88:80?\ ?--mount?type=bind,src=$(pwd)/nginx.conf,dst=/usr/local/nginx/conf/nginx.conf?--mount?src=wwwroot,dst=/wwwroot?nginx:v1? 5、以wordpress博客為例?https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
實戰演練:
創建自定義網絡 [root@localhost?~]#?docker?network?create?lnmp e206a2a632cf78430fc6c32d6f50a810c0a8f3ad8ad32287b354cad32de04aac [root@localhost?~]#? [root@localhost?~]#?docker?network?ls NETWORK?ID??????????NAME????????????????DRIVER??????????????SCOPE 67d8c68783da????????bridge??????????????bridge??????????????local 2b6c8c029f58????????host????????????????host????????????????local e206a2a632cf????????lnmp????????????????bridge??????????????local fc002cd520b3????????none????????????????null????????????????local [root@localhost?~]#? 查看創建的容器 [root@localhost?~]#?docker?ps?-a CONTAINER?ID????????IMAGE???????????????COMMAND?????????????CREATED?????????????STATUS??????????????PORTS???????????????NAMES [root@localhost?~]# 查看創建的卷: [root@localhost?~]#?docker?volume?ls DRIVER??????????????VOLUME?NAME [root@localhost?~] 創建Mysql容器 docker?run?-d?\ ?--name?lnmp_mysql?\ ?--net?lnmp?\ ?--mount?src=mysql-vol,dst=/var/lib/mysql?\ ?-e?MYSQL_ROOT_PASSWORD=123456?-e?MYSQL_DATABASE=wordpress?mysql:5.7??--character-set-server=utf8 創建PHP容器? docker?run?-d?--name?lnmp_php?--net?lnmp?--mount?src=wwwroot,dst=/wwwroot?php:v1 創建Nginx容器? docker?run?-d?--name?lnmp_nginx?--net?lnmp?-p?88:80?\ ?--mount?type=bind,src=$(pwd)/nginx.conf,dst=/usr/local/nginx/conf/nginx.conf?--mount?src=wwwroot,dst=/wwwroot?nginx:v1??#保證當前目錄下有nginx.conf文件 ? 掛載后會自動創建本地卷mysql-vol、wwwroot [root@localhost?first_stage]#?docker?volume?ls DRIVER??????????????VOLUME?NAME local???????????????mysql-vol local???????????????wwwroot [root@localhost?first_stage]#?docker?ps?-a???? CONTAINER?ID????????IMAGE???????????????COMMAND??????????????????CREATED?????????????STATUS??????????????PORTS?????????????????NAMES e09f16c2e561????????nginx:v1????????????"nginx?-g?'daemon?of…"???55?seconds?ago??????Up?54?seconds???????0.0.0.0:88->80/tcp????lnmp_nginx cc9ca12735fd????????php:v1??????????????"php-fpm"????????????????4?minutes?ago???????Up?4?minutes????????9000/tcp??????????????lnmp_php 22217c6c82ce????????mysql:5.7???????????"docker-entrypoint.s…"???5?minutes?ago???????Up?5?minutes????????3306/tcp,?33060/tcp???lnmp_mysql [root@localhost?first_stage]# 創建靜態測試頁面: [root@localhost?first_stage]#?ls?/var/lib/docker/volumes/wwwroot/_data/ [root@localhost?first_stage]# [root@localhost?first_stage]#?echo?"<h2>Hello,World.</h2>">/var/lib/docker/volumes/wwwroot/_data/index.html 瀏覽器訪問: http://192.168.16.121:88/??顯示內容為:Hello,World. 創建動態測試頁面: [root@localhost?first_stage]#?echo?"<?php?phpinfo();??>">/var/lib/docker/volumes/wwwroot/_data/test.php 瀏覽器訪問: http://192.168.16.121:88/test.php??顯示內容為:Hello,World. 部署wordpress博客: [root@localhost?first_stage]#?wget?https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz [root@localhost?first_stage]#?rm?-rf?/var/lib/docker/volumes/wwwroot/_data/* [root@localhost?first_stage]#?tar?xf?wordpress-4.9.4-zh_CN.tar.gz? [root@localhost?first_stage]#?mv?wordpress/*?/var/lib/docker/volumes/wwwroot/_data/ 瀏覽器訪問: http://192.168.16.121:88/index.php??顯示內容為:WordPress部署向導. 數據庫名:wordpress 用戶名:root 密碼:123456 數據庫主機:lnmp_mysql 表前綴:wp_ 提交 手工創建wp-config.php文件/var/lib/docker/volumes/wwwroot/_data/wp-config.php 現在安裝 站點標題:Jacky 用戶名:admin 密碼:123456 確認密碼:勾選“確認使用弱密碼” 您的電子郵件:admin@123.com 安裝WordPress
WordPress安裝向導如下所示:
到此為止,WordPress博客已搭建成功了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。