1. Operating system
Preparation: ubuntu22 machine
Basics: docker: [Selected] Docker Microservices-Basics_v2/_catalog-CSDN Blog
2. Install Docker
# Add Docker’s official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a + r /etc/apt/keyrings/docker.gpg# Add the repository to Apt sources:
echo \
“deb [arch=”$(dpkg –print-architecture)” signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
“$(. /etc/os-release & amp; & amp; echo “$VERSION_CODENAME”)” stable” | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get updatecurl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add –
sudo add-apt-repository “deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable”
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
3. Build image (nginx + php)
Ubuntu22.04 + nginx1.18 + php7.4
Dockerfile is as follows
FROM ubuntu:22.04 MAINTAINER itdd ENV MYPATH /tmp/php WORKDIR$MYPATH RUN apt-get -y update #Install vim editor RUN apt-get -y install vim RUN apt-get -y install lrzsz #Install the ifconfig command to view the network IP RUN apt-get -y install net-tools # nginx dependencies RUN apt-get install -y gcc RUN apt-get install -y libpcre3 libpcre3-dev RUN apt-get install -y zlib1g zlib1g-dev #RUN apt-get install -y openssl RUN apt-get install -y libssl-dev # Install nginx RUN apt-get install -y make RUN mkdir -p /usr/local/nginx ADD nginx-1.18.0.tar.gz /usr/local/nginx RUN cd /usr/local/nginx/nginx-1.18.0/ & amp; & amp; ./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/local/nginx/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ & amp; & amp; make \ & amp; & amp; make install RUN ln -s /usr/local/nginx/sbin/nginx /usr/bin/ RUN cd /usr/lib & amp; & amp; ln -s libXtst.so.6 libXtst.so RUN apt-get install -y libxtst-dev # Install php # If you do not select a time zone, you can skip this step by configuring environment variables. ARG DEBIAN_FRONTEND=noninteractive RUN echo "6" | apt-get install -y pkg-config # Add PHP repository RUN apt-get install -y software-properties-common RUN add-apt-repository ppa:ondrej/php RUN apt-get -y update #Install php extension dependencies RUN apt-get -y install gcc make curl libssl-dev php7.4-gd \ libxml2 libxml2-dev libzip-dev libcurl4-openssl-dev libpng-dev libjpeg-dev \ libwebp-dev libonig-dev libsqlite3-dev libsodium-dev libjpeg-dev libgd-dev \ libpng-dev libargon2-dev libfreetype6-dev libreadline6-dev \ libsqlite3-dev libzip-dev RUN mkdir -p /tmp/php/ ADD php-7.4.30.tar.gz /tmp/php/ #php7.4 needs to lower the openssl version RUN apt-get install -y perl RUN mkdir -p /tmp/openssl/ ADD openssl-1.1.1.tar.gz /tmp/openssl RUN cd /tmp/openssl/openssl-1.1.1/ RUN cd /tmp/openssl/openssl-1.1.1/ & amp; & amp; ./Configure \ --prefix=/opt/build \ --openssldir=/opt/build \ -fPIC \ -shared \ linux-x86_64 \ -Wl,--enable-new-dtags,-rpath,'/opt/build/lib' \ & amp; & amp; make & amp; & amp; make install # Install php RUN export PKG_CONFIG_PATH=/opt/build/lib/pkgconfig \ & amp; & amp; export LD_LIBRARY_PATH=/opt/build/lib \ & amp; & amp; export OPENSSL_CONF=/etc/ssl \ & amp; & amp; cd /tmp/php/php-7.4.30/ & amp; & amp; ./configure --prefix=/usr/local/php-7.4.30 \ --with-config-file-path=/usr/local/php-7.4.30/etc \ --with-fpm-user=www \ --with-fpm-group=www \ --with-openssl=/opt/build \ --enable-mysqlnd \ --with-pdo-mysql \ --with-jpeg \ --with-gd \ --enable-bcmath \ --enable-fpm \ --enable-phpdbg \ --enable-shmop \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-zip \ --with-zlib \ --enable-pcntl \ --with-readline \ --with-pear \ --with-freetype \ --enable-gd \ --with-pdo-mysql=mysqlnd \ --enable-mbstring \ --enable-sockets \ --with-curl --enable-fpm \ & amp; & amp; make \ & amp; & amp; make install \ & amp; & amp; cp php.ini-development /usr/local/php-7.4.30/etc/php.ini ADD php-fpm.conf /usr/local/php-7.4.30/etc/php-fpm.conf ADD www.conf /usr/local/php-7.4.30/etc/php-fpm.d/www.conf ADD nginx.conf /etc/nginx/nginx.conf #Copy code to environment #ADD mycms-master.zip /usr/local/nginx/html RUN groupadd www RUN useradd -g www www # Start the file into the image ADD startServer.sh /tmp/php/startServer.sh RUN chmod +x /tmp/php/startServer.sh EXPOSE 80 443 ENTRYPOINT ["./startServer.sh"]
The files involved are all in the package file at the beginning of the article. They were all created step by step by my own hands. They are all hard work.
If you don’t give me some money, I can’t help you, brother. Hehehe! ! ! ! !
Note: There is a path line at the bottom of php-fpm.conf, change it to your own path.
For details, please refer to Docker microservice-Dockerfile of Nginx + PHP_php dockerfile_IT Dongdonge’s blog-CSDN blog
4. Create a PHP container
docker build -t ubuntu-nginx-php:1.0 . # Map configuration files and projects to facilitate modification and debugging docker run --name=php-pv1 -p 8001:80 -d \ -v /data1/docker/src/config_pv/nginx.conf:/etc/nginx/nginx.conf \ -v /data1/docker/src/config_pv/php.ini:/usr/local/php-7.4.30/etc/php.ini \ -v /data1/docker/src/config_pv/html:/usr/local/nginx/html \ ubuntu-nginx-php:1.0
If the container creation fails, you can check the log
5. Create data Mysql container
Provide data support for PHP projects:
docker run -p 3306:3306 –name=easyadmin \
-v /data1/docker/src/mysql8.0/log:/var/log/mysql \
-v /data1/docker/src/mysql8.0/data:/var/lib/mysql \
-v /data1/docker/src/mysql8.0/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0
After creating mysql8.0, an error will be reported when connecting with Navicat.
Restore the mysql user login password encryption rule to mysql_native_password.
ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
6. Visit
http://xxxx:8009/admin/login/index
login interface:
front page:
The membership system is basically developed
Success should look like this. If you bosses want to build your own platform, you can develop it again based on this foundation. If you have any questions, you can send me a private message. You can also communicate directly with + v: 17611675670.