1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > docker-compose.yml搭建lnmp

docker-compose.yml搭建lnmp

时间:2021-10-09 17:00:35

相关推荐

docker-compose.yml搭建lnmp

安装 docker-compose 以及 创建目录和文件!!!

[root@localhost ~]# curl -L "/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose% Total % Received % Xferd Average Speed Time TimeTime CurrentDload Upload Total Spent Left Speed100 633 100 633 00 9690 --:--:-- --:--:-- --:--:-- 967100 12.1M 100 12.1M 00 3185k0 0:00:03 0:00:03 --:--:-- 4502k[root@localhost ~]# lsanaconda-ks.cfg[root@localhost ~]# mkdir compose_lnmp[root@localhost ~]# cd compose_lnmp/[root@localhost compose_lnmp]# mkdir php[root@localhost compose_lnmp]# cd php/[root@localhost php]# vim Dockerfile[root@localhost php]# lsDockerfile[root@localhost php]# cd ..[root@localhost compose_lnmp]# lsphp[root@localhost compose_lnmp]# lsdocker-compose.yml php[root@localhost compose_lnmp]# ll /usr/local/bin/docker-compose -rw-r--r--. 1 root root 12737304 8月 11 01:10 /usr/local/bin/docker-compose[root@localhost compose_lnmp]# chmod +x /usr/local/bin/docker-compose[root@localhost compose_lnmp]# docker-compose --versiondocker-compose version 1.29.2, build 5becea4c[root@localhost compose_lnmp]# cd [root@localhost ~]# tree compose_lnmp/compose_lnmp/├── docker-compose.yml└── php└── Dockerfile1 directory, 2 files

编写php里面的 Dockerfile!!!

[root@localhost ~]# cat compose_lnmp/php/Dockerfile FROM php:7.0-fpmRUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo "Asia/Shanghai" > /etc/timezoneRUN apt-get update && apt-get install -y \libfreetype6-dev \libjpeg62-turbo-dev \libmcrypt-dev \libpng-dev \libmemcached-dev \zlib1g-dev \libcurl4-openssl-dev \libxml2-dev \--no-install-recommends && rm -rf /var/lib/apt/lists/* \&& docker-php-ext-install -j$(nproc) \iconv mcrypt gettext curl mysqli pdo pdo_mysql zip \mbstring bcmath opcache xml simplexml sockets hash soap \&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \&& docker-php-ext-install -j$(nproc) gdCMD ["php-fpm", "-F"]

编写docker-compose.yml!!

[root@localhost ~]# cat compose_lnmp/docker-compose.yml version: "3"services:mysql:hostname: mysqlrestart: alwaysimage: mysql:5.6container_name: mysqlports:- "3306:3306"volumes:- mysql-config:/etc/mysql- mysql-log:/var/log/mysql- mysql-data:/var/lib/mysqlenvironment:MYSQL_ROOT_PASSWORD: 123456MYSQL_USER: userMYSQL_PASSWORD: user123php:hostname: phprestart: alwayscontainer_name: phpbuild:context: ./phpdockerfile: Dockerfileports:- "9000:9000"links:- mysql:mysqlvolumes:- nginx-html:/var/www/html- php-config:/usr/local/etcnginx:hostname: nginxrestart: alwayscontainer_name: nginximage: nginx:1.17.0ports:- "80:80"- "443:443"links:- "php:php"volumes:- nginx-config:/etc/nginx- nginx-log:/var/log/nginx- nginx-html:/usr/share/nginx/htmlvolumes:mysql-config:mysql-log:mysql-data:nginx-html:php-config:nginx-config:nginx-log:

启动服务!!!

[root@localhost ~]# cd compose_lnmp/[root@localhost compose_lnmp]# docker-compose up -dCreating network "compose_lnmp_default" with the default driverCreating volume "compose_lnmp_mysql-config" with default driverCreating volume "compose_lnmp_mysql-log" with default driverCreating volume "compose_lnmp_mysql-data" with default driverCreating volume "compose_lnmp_nginx-html" with default driverCreating volume "compose_lnmp_php-config" with default driverCreating volume "compose_lnmp_nginx-config" with default driverCreating volume "compose_lnmp_nginx-log" with default driverPulling mysql (mysql:5.6)...5.6: Pulling from library/mysql778066204fb7: Pull complete4934b98a40c4: Pull complete24d0034f4cf8: Pull completecd5c81076c53: Pull complete3e630bfc5120: Pull completefc97236980ff: Pull complete9935fd852726: Pull completee25ac4a39a81: Pull completee8b50ae6b193: Downloading [==========>] 13.97MB/64.27MB9b0af3588a72: Download complete0a2c92fcf3d9: Download completeWARNING: Image for service php was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.Pulling nginx (nginx:1.17.0)...1.17.0: Pulling from library/nginxfc7181108d40: Pull completec4277fc40ec2: Pull complete780053e98559: Pull completeDigest: sha256:bdbf36b7f1f77ffe7bd2a32e59235dff6ecf131e3b6b5b96061c652f30685f3aStatus: Downloaded newer image for nginx:1.17.0Creating mysql ... doneCreating php ... doneCreating nginx ... done

查看容器!!!

[root@localhost compose_lnmp]# docker psCONTAINER ID IMAGE COMMAND CREATEDSTATUSPORTSNAMES9bb2dc9f4d1f nginx:1.17.0 "nginx -g 'daemon of…" 42 seconds ago Up 40 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp nginxb104b5b73386 compose_lnmp_php "docker-php-entrypoi…" 44 seconds ago Up 41 seconds 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp phpd4d563fe48ec mysql:5.6"docker-entrypoint.s…" 45 seconds ago Up 43 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp mysql

数据持久化目录!!!

[root@localhost compose_lnmp]# docker volume lsDRIVER VOLUME NAMElocalcompose_lnmp_mysql-configlocalcompose_lnmp_mysql-datalocalcompose_lnmp_mysql-loglocalcompose_lnmp_nginx-configlocalcompose_lnmp_nginx-htmllocalcompose_lnmp_nginx-loglocalcompose_lnmp_php-config

配置php!!!

[root@localhost compose_lnmp]# cd /var/lib/docker/volumes/compose_lnmp_php-config/_data/php[root@localhost php]# lsconf.d php.ini-development php.ini-production[root@localhost php]# cp php.ini-production php.ini[root@localhost php]# lsconf.d php.ini php.ini-development php.ini-production[root@localhost php]# vim php.ini; Defines the default timezone used by the date functions; /date.timezonedate.timezone = Asia/shanghai # 取消注释 修改时区!

配置nginx!!!

[root@localhost php]# vim /var/lib/docker/volumes/compose_lnmp_nginx-config/_data/conf.d/default.conflocation / {root /usr/share/nginx/html;index index.html index.htm index.php; #添加index.php}location ~ \.php$ {root html;fastcgi_pass php:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;include fastcgi_params;}

测试 mysql!!!

[root@localhost php]# docker container exec -it mysql bashroot@mysql:/# mysql -uroot -p123456Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.51 MySQL Community Server (GPL)Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

php页面!!

[root@localhost php]# vim /var/lib/docker/volumes/compose_lnmp_nginx-html/_data/index.php[root@localhost php]# cat /var/lib/docker/volumes/compose_lnmp_nginx-html/_data/index.php<?phpphpinfo();?>

重启所有容器!!!

[root@localhost ~]# cd compose_lnmp/[root@localhost compose_lnmp]# docker-compose restartRestarting nginx ... doneRestarting php ... doneRestarting mysql ... done[root@localhost compose_lnmp]# ss -antlState Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:9000 0.0.0.0:* LISTEN 0 128 0.0.0.0:3306 0.0.0.0:* LISTEN 0 128 0.0.0.0:800.0.0.0:* LISTEN 0 128 0.0.0.0:220.0.0.0:* LISTEN 0 128 0.0.0.0:443 0.0.0.0:* LISTEN 0 128[::]:9000 [::]:* LISTEN 0 128[::]:3306 [::]:* LISTEN 0 128[::]:80 [::]:* LISTEN 0 128[::]:22 [::]:* LISTEN 0 128[::]:443

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。