使用docker-compose来build构建部署lnmp
创建目录 将安装包放到对应目录
root@ubuntu20:~# mkdir nginx mysql php
root@ubuntu20:~# mv nginx-1.15.4.tar.gz nginx
root@ubuntu20:~# mv mysql-5.5.22.tar.gz mysql
root@ubuntu20:~# mv php-5.3.28.tar.gz php
Nginx
root@ubuntu20:~/nginx# vim Dockerfile
添加:
FROM centos:7
RUN yum -y install net-tools coreutils chkconfig iproute sed \
pcre-devel ncurses-devel openssl-devel zlib-devel autoconf \
libjpeg-devel libxml2-devel libpng-devel gd gcc gcc-c++ make perl perl-develRUN yum -y install net-tools iproute pcre-devel openssl-devel gcc gcc-c++ make zlib-devel elinks
ADD nginx-1.15.4.tar.gz /usr/class="lazy" data-src
ENV NGINX_DIR /usr/class="lazy" data-src/nginx-1.15.4
WORKDIR $NGINX_DIR
RUN ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make && make install
WORKDIR /
RUN useradd nginx
RUN ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
Php
root@ubuntu20:~/php# vim Dockerfile
添加:
FROM centos:7
RUN yum -y install net-tools coreutils chkconfig iproute sed \
pcre-devel ncurses-devel openssl-devel zlib-devel autoconf php-mysql mysql-devel \
libjpeg-devel libxml2-devel libpng-devel gd gcc gcc-c++ make perl perl-develENV PHP_INSTALL_DIR /usr/class="lazy" data-src/php-5.3.28
ENV PHP_DIR /usr/local/php
ENV PHP_SH /etc/init.d/php-fpm
ADD php-5.3.28.tar.gz /usr/class="lazy" data-src
RUN yum -y install net-tools coreutils chkconfig iproute sed \
pcre-devel ncurses-devel openssl-devel zlib-devel autoconf \
libjpeg-devel libxml2-devel libpng-devel gd gcc gcc-c++ make perl perl-develWORKDIR /
WORKDIR $PHP_INSTALL_DIR
RUN ./configure --prefix=$PHP_DIR --with-gd --with-zlib \
--with-config-file-path=$PHP_DIR \
--enable-fpm --enable-mbstring --with-jpeg-dir=/usr/lib && make && make install
WORKDIR /
RUN cp $PHP_INSTALL_DIR/php.ini-development $PHP_DIR/php.ini
RUN cp $PHP_INSTALL_DIR/sapi/fpm/init.d.php-fpm $PHP_SH
RUN chmod +x $PHP_SH && chkconfig --add php-fpm
RUN cp $PHP_DIR/etc/php-fpm.conf.default $PHP_DIR/etc/php-fpm.conf
RUN mkdir /www/php -p
RUN useradd -M -s /sbin/nologin nginx
COPY php.sh /root/php.sh
RUN chmod +x /root/php.sh
EXPOSE 9000
CMD ["/root/php.sh"]
root@ubuntu20:~/php# vim php.sh
添加:
#!/bin/bash
/etc/init.d/php-fpm start
/bin/bash
root@ubuntu20:~# vim docker-compose.yaml
修改:
version: "3"
services:
nginx:
container_name: nginx
build: ~/nginx
volumes:
- nginx_dir:/usr/local/nginx/conf/
links:
- php:phpfpm
restart: always
ports:
- "80:80"
hostname: nginx
networks:
- lnmp_net
mysql:
image: mysql:5.7
volumes:
- mysql_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123.com
MYSQL_DATABASE: todos
networks:
- lnmp_net
php:
hostname: php
container_name: php
build: ~/php
volumes:
- php_dir:/usr/local/php/
- php_index:/www/php
restart: always
ports:
- "9000:9000"
stdin_open: true
networks:
- lnmp_net
volumes:
nginx_dir:
mysql_data:
php_dir:
php_index:
networks:
lnmp_net:
driver: bridge
构建镜像
root@ubuntu20:~# docker-compose build
root@ubuntu20:~# docker-compose up –d
编辑配置文件
root@ubuntu20:~# vim /var/lib/docker/volumes/root_nginx_dir/_data/nginx.conf
添加:
编辑php配置文件
root@ubuntu20:~# vim /var/lib/docker/volumes/root_php_dir/_data/php.ini
添加:
root@ubuntu20:~# vim /var/lib/docker/volumes/root_php_dir/_data/etc/php-fpm.conf
修改添加:
Bianji 配置文件
root@ubuntu20:~# vim /var/lib/docker/volumes/root_php_index/_data/index.php
手动添加:
编辑配置文件
root@ubuntu20:~# vim /var/lib/docker/volumes/root_php_index/_data/mysql.php
手动添加:
数据库授权
root@ubuntu20:~# docker exec -it root_mysql_1 mysql -u root -p123.com
mysql> grant all on *.* to 'root'@'%' identified by '123.com';
Query OK, 0 rows affected, 1 warning (0.00 sec)
进入php容器进行配置编译安装
root@ubuntu20:~# docker exec -it php bash
[root@php /]# cd /usr/class="lazy" data-src/php-5.3.28/
[root@php php-5.3.28]# ./configure --prefix=/usr/local/php --with-gd --with-zlib --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-config-file-path=/usr/local/php --enable-fpm --enable-mbstring --with-jpeg-dir=/usr/lib && make && make install
重启php服务
[root@php php-5.3.28]# /etc/init.d/php-fpm restart
进入到mysql容器重启服务
root@ubuntu20:~# docker exec -it root_mysql_1 bash
root@c21e5a16202e:/# /etc/init.d/mysql restart
[info] Stopping MySQL Community Server 5.7.36.
进入到nginx容器重启服务
root@ubuntu20:~# docker exec -it nginx bash
[root@nginx /]# nginx -s reload
浏览器访问
192.168.0.143/index.php
192.168.0.143/mysql.php
192.168.0.143
来源地址:https://blog.csdn.net/weixin_53053517/article/details/130747320
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341