In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Now containerization technology is becoming more and more mature and popular, which really has great advantages over traditional virtualization technology, so popularity is inevitable. Let's put it into practice today and customize the lnmp environment using Docker's dockerfile approach.
Environment configuration operating system: CentOS Linux release 7.6.1810Docker version: 19.03.5Nginx version: 1.15.5PHP version: 7.2.26MySQL version: 8.0.18Redis version: 5.0.5 create directory structure docker directory: / / docker related configuration [root@zhangdeTalk data] # tree dockerdocker ├── bin │ └── docker-compose-linux.yml / / dockerfile.yml ├── config │ ├── mysql │ │ └── mysqld.cnf / / Database configuration file │ ├── nginx │ │ ├── conf.d │ └── default.conf / / nginx main configuration file │ │ └── nginx.conf / / nginx basic configuration file │ ├── php │ │ ├── php.ini / / php basic configuration file │ │ www .conf / / php main configuration file │ └── redis │ └── redis.conf / / redis configuration file ├── dockerfile │ ├── mysql-8.0.18 │ │ └── Dockerfile / / mysql dockerfile │ ├── nginx-1.15.5 │ │ └── Dockerfile / / nginx dockerfile │ ├── php-7.2-fpm │ Dockerfile / / php Dockerfile │ └── redis-5.0.5 │ └── Dockerfile / / redis dockerfile ├── README.en.md └── README.mdwww directory: / / site directory [root@zhangdeTalk data] # tree wwwwww └── zhangdetalk_blog_admin ├── 1.html └── index.phplogs directory: / / log directory [root@zhangdeTalk data] # tree logslogs ├── mysql ├── nginx │ ├── access.log │ └── Error.log ├── php └── redismysql directory: / / database data directory redis directory: / / database data directory Docker installation
First install Docker in CentOS, you can refer to another article: CentOS install Docker
Build lnmp image DockerfilePHP DockerfileFrom php:7.2-fpm# maintainer information MAINTAINER zhangdeTalk 2393222021@qq.com# time zone ENV TZ Asia/ShanghaiRUN date-R#RUN docker-php-ext-install bcmath dom fileinfo filter ftp gd gmp hash iconv imap json mbstring mysqli odbc opcache pdo pdo_mysql pdo_odbc phar reflection session snmp soap sockets zip#RUN docker-php-ext-install mysqli opcache pdo_mysqlWORKDIR / workingRUN apt-get update-- fix-missing & & apt-get install-y libpng-dev libjpeg-dev libfreetype6-dev\ & & docker-php-ext-configure gd-- with-freetype-dir=/usr/include-- with-jpeg-dir=/usr/include/jpeg\ & & docker-php-ext-install gd mysqli opcache pdo_mysql gd zipENV PHPREDIS_VERSION 4.0.1ENV PHPXDEBUG_VERSION 2.6.0ENV PHPSWOOLE_VERSION 4.2.13ENV PHPMONGODB_VERSION 1.5.3RUN pecl install redis-$PHPREDIS_VERSION\ & pecl install xdebug-$PHPXDEBUG_VERSION\ & & pecl install swoole-$PHPSWOOLE_VERSION\ & & pecl install mongodb-$PHPMONGODB_VERSION\ & & docker-php-ext-enable redis xdebug swoole mongodb# install composer new# https://getcomposer.org/installer | https://install.phpcomposer.com/installer RUN php- r "copy ('https://getcomposer.org/installer', 'composer-setup.php') "\ & & php composer-setup.php\ & & php-r" unlink ('composer-setup.php') "\ & & mv composer.phar / usr/local/bin/composer\ & & composer config-g repo.packagist composer https://packagist.laravel-china.orgRUN apt-get install-y git# clearRUN rm-rf / var/cache/apt/*\ & & rm-rf / var/lib/apt/lists/*RUN mkdir / var/lib/sessions\ & & chmod o=rwx-R / var/lib/sessions# container executes the instruction CMD when it starts [" Php-fpm "] Nginx DockerfileFrom nginx:1.15.5# maintainer information MAINTAINER zhangdeTalk 2393222021@qq.com# time zone ENV TZ Asia/ShanghaiRUN date-R# container executes the instruction CMD [" nginx "when the container starts "- g", "daemon off "] Mysql DockerfileFrom mysql:8.0.18# maintainer information MAINTAINER zhangdeTalk 2393222021@qq.com# time zone ENV TZ Asia/ShanghaiRUN date-R# container startup execution instruction CMD [" mysqld "] Redis DockerfileFrom redis:5.0.5# maintainer information MAINTAINER zhangdeTalk 2393222021@qq.com# time zone ENV TZ Asia/ShanghaiRUN date-R# container startup execution instruction CMD [" redis-server "] dockerfile.yml configuration version: '3.3'services: nginx: Build:.. / dockerfile/nginx-1.15.5 ports:-"80:80" # nginx restart: always tty: true container_name: nginx volumes:-/ data/www:/var/www/html-/ data/logs/nginx:/var/log/nginx-/ data/docker/config/nginx/conf.d:/etc/nginx/conf.d-/ data/docker/ Config/nginx/nginx.conf:/etc/nginx/nginx.conf-/ etc/letsencrypt:/etc/letsencrypt networks:-lnmp-networks php7: build:.. / dockerfile/php-7.2-fpm tty: true restart: always container_name: php7 volumes:-/ data/www:/var/www/html-/ data/logs/php:/var/log/php-/ data/docker/ Config/php/php.ini:/usr/local/etc/php/php.ini-/ data/docker/config/php/www.conf:/usr/local/etc/php-fpm.d/www.conf depends_on:-nginx networks:-lnmp-networks redis: build:.. / dockerfile/redis-5.0.5 container_name: redis tty: true restart: always volumes:-/ data/docker/ Config/redis/redis.conf:/etc/redis/redis.conf-/ data/redis:/var/lib/redis-/ data/logs/redis:/var/log/redis networks:-lnmp-networks mysql: build:.. / dockerfile/mysql-8.0.18 container_name: mysql tty: true restart: always ports:-"3306 virtual 3306" # mysql volumes:-/ data/ Mysql:/var/lib/mysql-/ data/docker/config/mysql/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf-/ data/logs/mysql:/var/log/mysql-/ data/mysqlback:/data/mysqlback environment: MYSQL_ROOT_PASSWORD: root networks:-lnmp-networksnetworks: lnmp-networks:Nginx configuration file vim / data/docker/config/nginx/conf.d/default.confserver {listen 80 Listen [:]: 80; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html index.php; charset utf-8; server_name zhangdetalk.com www.zhangdetalk.com; location ~\ .md$ {default_type 'text/plain';} root / var/www/html/zhangdetalk_blog_admin / / Project directory location / {# try_files $uri $uri/ = 404; index index.php index.htm index.html; if (!-e $request_filename) {rewrite ^ (. *) $/ index.php?s=$1 last; break }} location ~\ .php$ {include fastcgi_params; fastcgi_index index.php; fastcgi_pass php7:9000;// container: Port number fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name }} docker-compose install 1. Curl-L https://get.daocloud.io/docker/compose/releases/download/1.22.0/docker-compose-`uname-s`-`uname-m` > / usr/local/bin/docker-compose2. Chmod + x / usr/local/bin/docker-compose / / set executable permissions to create and launch container docker-compose- f docker-compose-linux.yml up-d-- force-recreate-- remove-orphans container view docker ps
Test vim / data/www/zhangdetalk_blog_admin/index.php
By visiting the site: http://www.zhangdetalk.com/ can see that the database connection is successful and print out the relevant information about PHP. At this step, the construction of our lnmp environment is complete! Download address of source code related to github source code: 1. PHP code connects to the database. Host cannot be written as 127.0.0.1 or localhost. You need to enter the name of the database container.
2. Mysql8 connection failed because there is a change in the encryption method: the host logs in to mysql, modifies it to the old encryption method (mysql_native_password), and resets the password * mysql-uroot-p * use mysql;* select host,user,plugin from user;* alter user 'root'@'%' identified with mysql_native_password by' 123456'
You can refer to this article: Docker install MySQL8.0
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.