Create a directory and place the installation package in the corresponding directory
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
Add to:
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/src
ENV NGINX_DIR /usr/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
Add to:
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/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/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
Add to:
#!/bin/bash
/etc/init.d/php-fpm start
/bin/bash
root@ubuntu20:~# vim docker-compose.yaml
Revise:
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
Build image
root@ubuntu20:~# docker-compose build
root@ubuntu20:~# docker-compose up –d
Edit configuration file
root@ubuntu20:~# vim /var/lib/docker/volumes/root_nginx_dir/_data/nginx.conf
Add to:
Edit php configuration file
root@ubuntu20:~# vim /var/lib/docker/volumes/root_php_dir/_data/php.ini
Add to:
root@ubuntu20:~# vim /var/lib/docker/volumes/root_php_dir/_data/etc/php-fpm.conf
Modify and add:
Bianji configuration file
root@ubuntu20:~# vim /var/lib/docker/volumes/root_php_index/_data/index.php
add manully:
Edit configuration file
root@ubuntu20:~# vim /var/lib/docker/volumes/root_php_index/_data/mysql.php
add manully:
Database authorization
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)
Enter the php container to configure, compile and install
root@ubuntu20:~# docker exec -it php bash
[root@php /]# cd /usr/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
Restart php service
[root@php php-5.3.28]# /etc/init.d/php-fpm restart
Enter the mysql container and restart the service
root@ubuntu20:~# docker exec -it root_mysql_1 bash
root@c21e5a16202e:/# /etc/init.d/mysql restart
[info] Stopping MySQL Community Server 5.7.36.
Enter the nginx container and restart the service
root@ubuntu20:~# docker exec -it nginx bash
[root@nginx /]# nginx -s reload
Browser access
192.168.0.143/index.php
192.168.0.143/mysql.php
192.168.0.143