Docker是一個開源的應用容器引擎,基於Go語言並聽從Apache2.0協議開源。php
Docker可讓開發者打包他們的應用以及依賴包到一個輕量級、可移植的容器中,而後發佈到任何流行的Linux機器上,也能夠實現虛擬化。容器是徹底使用沙箱機制,相互之間不會有任何接口(相似iPhone的app),更重要的是容器性能開銷極低。node
文章就不介紹如何去安裝和使用docker了。不會的請你們自行谷歌/百度去學習下~mysql
最新版的鏡像地址,在個人阿里雲倉庫裏面,文章末尾,能夠直接使用命令docker pull獲取。linux
先說下本人docker中部署lnmp環境使用的幾個方法:nginx
方法一:經過百度等方法,分別從一些鏡像倉庫拉取nginx、mysql、php鏡像,而後掛在數據卷並映射端口。c++
附參考飛機票:https://learnku.com/articles/9200/centos-7-uses-docker-to-build-a-basic-lnmp-environmentredis
但因爲我想要一個統一的lnmp環境,因此放棄了這個方法。sql
方法二:經過Dockerfile,寫一些命令,逐步安裝各個app及擴展。但因爲中途有一些報錯,排查了好久,安裝過程有些繞,最終放棄。貼出dockerfile代碼,你們能夠試用一下,若是有能力排除問題,也可使用。mongodb
# base image # 基礎鏡像 FROM centos:latest # MAINTAINER編寫者 LABEL MAINTAINER mengyilingjian@outlook.com # put nginx-1.16.1.tar.gz into /usr/local and unpack nginx 來吧nginx 和PHP提早都放進基礎鏡像的/usr/local/src目錄下,方便編譯安裝 ADD nginx-1.16.1.tar.gz /usr/local ADD php-7.3.8.tar.gz /usr/local # running required command 安裝Nginx的一系列亂七八糟的依賴包 RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel bison libcurl-devel RUN yum install -y libxslt-devel -y gd gd-devel GeoIP GeoIP-devel pcre pcre-devel RUN useradd -M -s /sbin/nologin nginx # change dir to /usr/local/nginx-1.16.1 WORKDIR /usr/local/nginx-1.16.1 # execute command to compile nginx RUN ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install EXPOSE 80 443 #先裝個本地Mysql RUN yum install -y wget RUN wget http://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm RUN rpm -ivh mysql80-community-release-el7-3.noarch.rpm --force --nodeps RUN yum install -y mysql-server #截止此,開始安裝php,宇宙慣例,開始安裝一些編譯的依賴包 RUN yum -y install epel-release RUN yum -y install libmcrypt-devel RUN yum -y install libxml2 libxml2-devel openssl curl-devel libjpeg-devel libpng-devel freetype-devel WORKDIR /usr/local/php-7.3.8 #編譯 安裝 RUN ./configure --prefix=/usr/local/php7.3.8 --with-config-file-path=/usr/local/php7.3.8/etc --with-config-file-scan-dir=/usr/local/php7.3.8/etc/php.d --with-mcrypt=/usr/include --enable-mysqlnd --with-mysqli --with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-gd --with-iconv --with-zlib --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache && make && make install \ && cp /usr/local/php7.3.8/etc/php-fpm.conf.default /usr/local/php7.3.8/etc/php-fpm.conf \ && cp /usr/local/php7.3.8/etc/php-fpm.d/www.conf.default /usr/local/php7.3.8/etc/php-fpm.d/www.conf \ && sed -i '/;daemonize/a\daemonize = no' /usr/local/php7.3.8/etc/php-fpm.conf \ && sed -i 's/127.3.8.1/0.0.0.0/g' /usr/local/php7.3.8/etc/php-fpm.d/www.conf \ && echo "${TIME_ZOME}" > /etc/timezone \ && ln -sf /usr/share/zoneinfo/${TIME_ZOME} /etc/localtime \ && yum clean all \ && yum -y remove gcc gcc-c++ make EXPOSE 9000 CMD ["sbin/php-fpm","-c","etc/php-fpm.conf"] RUN cp php.ini-production /usr/local/php7.3.8/etc/php.ini方法三:在centos中,經過lnmp一鍵安裝包,進行安裝。這個方法貌似能夠成功,可是耗費時間會根據網絡和服務器配置的高低,變得漫長而痛苦。因爲本人服務器本身用,因此配置不高,耗費了接近十多個小時,中途沒有報錯。因此有點啼笑皆非。最後仍是放棄。docker
1.文章教程使用配置環境:
[root@izwz91quxhnlk8xexo852xz ~]# docker --version Docker version 19.03.1, build 74b1e89 [root@izwz91quxhnlk8xexo852xz ~]# df -hl Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G 19G 19G 51% / devtmpfs 909M 0 909M 0% /dev tmpfs 920M 0 920M 0% /dev/shm tmpfs 920M 556K 919M 1% /run tmpfs 920M 0 920M 0% /sys/fs/cgroup tmpfs 184M 0 184M 0% /run/user/0 overlay 40G 19G 19G 51% /var/lib/docker/overlay2/22a5b83dd224ee73588dcbc58c5d618e9d91398f57389ba3a3632aed7e853365/merged [root@izwz91quxhnlk8xexo852xz ~]# nginx -V nginx version: nginx/1.16.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) built with OpenSSL 1.1.1b 26 Feb 20192.lnmp環境搭建成功的詳細信息:
php7:
[root@9c73e764fc4b bin]# ./php --version PHP 7.3.8 (cli) (built: Aug 22 2019 09:34:04) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies with the ionCube PHP Loader + ionCube24 v10.3.7, Copyright (c) 2002-2019, by ionCube Ltd. with Zend OPcache v7.3.8, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans Segmentation fault (core dumped) [root@9c73e764fc4b bin]# ./php -m [PHP Modules] bcmath Core ctype curl date dom exif fileinfo filter ftp gd gettext hash iconv intl ionCube Loader json libxml mbstring memcache memcached mongodb mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_sqlite phalcon Phar posix redis Reflection session shmop SimpleXML soap sockets sodium SPL sqlite3 standard swoole sysvsem tokenizer xdebug xml xmlreader xmlrpc xmlwriter xsl yaf Zend OPcache zip zlibphp5.6:
[root@9c73e764fc4b bin]# ./php --version PHP 5.6.40 (cli) (built: Aug 22 2019 10:06:15) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with the ionCube PHP Loader + ionCube24 v10.3.7, Copyright (c) 2002-2019, by ionCube Ltd. with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans [root@9c73e764fc4b bin]# ./php -m [PHP Modules] bcmath Core ctype curl date dom ereg exif fileinfo filter ftp gd gettext hash iconv intl ionCube Loader json libxml mbstring mcrypt memcache memcached mhash mongodb mysql mysqli mysqlnd openssl pcntl pcre PDO pdo_mysql pdo_sqlite phalcon Phar posix redis Reflection session shmop SimpleXML soap sockets SPL sqlite3 standard swoole sysvsem tokenizer xdebug xml xmlreader xmlrpc xmlwriter xsl Zend Guard Loader Zend OPcache zip zlibmysql8.0:
[root@9c73e764fc4b bin]# ./mysql --version ./mysql Ver 8.0.17 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)nginx:
[root@9c73e764fc4b sbin]# ./nginx -V nginx version: nginx/1.16.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)3.宿主機中經過如下命令可拉取個人阿里雲倉庫裏最新的的centos-lnmp鏡像,歡迎你們下載使用。有問題能夠加微信與我溝通:
registry.cn-shenzhen.aliyuncs.com/eric_zhou/public:lnmp-v2.0
[root@izwz91quxhnlk8xexo852xz ~]# docker pull registry.cn-shenzhen.aliyuncs.com/eric_zhou/public:lnmp-v2.0 [root@izwz91quxhnlk8xexo852xz ~]# docker exec -it [imageID] /bin/bash ----------------------------------------------------------------------------------------- php mysql nginx 已經加入全局變量,須要執行如下命令方可生效: source /etc/profile
不懂地方可留言,或者進微信羣內交流。
羣二維碼:
羣二維碼若是過時,請加我我的微信:mengyilingjian.