Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of Docker Application example

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "Docker Application case Analysis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Install Nginx

Running an Alpine container, Alpine is chosen as the system base image because of the lightweight size of Alpine, and the basic image is only 5.53MB, which is ten times smaller than the 88.9MB of ubuntu image.

Root@ubuntu:~# docker run-it-p 8080 alpine sh

Install nginx

Apk add nginx

Modify nginx configuration

Vi / etc/nginx/conf.d/default.conf

The default.conf content is as follows:

Server {listen 80 default_server; root / home/www; index index.php index.html;}

Create Hello World

Mkdir / home/www & & echo "Hello World" > / home/www/index.html

Create / run/nginx directory

Mkdir / run/nginx

Start nginx

Nginx

Access http://192.168.43.122:8080 in a browser

Nginx installed successfully and WEB service access is normal!

Install PHP

Now let's install PHP in the same way, using the apk add command to install php7,php-fpm and related extensions.

Apk add-no-cache php7 php7-fpm php7-ftp php7-pdo php7-mysqli php7-simplexml php7-xmlwriter php7-zlib php7-imagick php7-memcached php7-sockets php7-mcrypt php7-zip php7-pgsql php7-pdo_odbc php7-odbc php7-curl php7-iconv php7-xml php7-json php7-gd php7-session php7-opcache php7-pdo_sqlite php7-mbstring php7-common php7-pdo_mysql

A lot of php extensions have been installed in the above, which can be increased or decreased according to the actual demand.

Now start php-fpm7

Php-fpm7

Modify nginx configuration and add php support

Vi / etc/nginx/conf.d/default.conf

The contents are as follows

Server {listen 80 default_server; root / home/www; index index.php index.html; location ~\ .php$ {try_files $uri = 404; fastcgi_split_path_info ^ (. +\ .php) (/. +) $; fastcgi_pass 127.0.0.1 home/www; index index.php index.html; location 9000 Fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME / home/www$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info;}}

Create a phpinfo.php in the site directory

Echo "" > / home/www/phpinfo.php

Restart nginx

Nginx-s reload

Access http://192.168.43.122:8080/phpinfo.php in a browser

PHP installed successfully and WEB service access is normal!

Using MySQL services

We do not install MySQL in Alpine. For efficiency, we can directly use the official image here, open a new ssh terminal to connect to the host, and create a new database directory under the home directory.

Mkdir / home/database

Run a container with an official mysql5.7 image, set the root password to 123456, map port 3306, and mount the host / home/database directory to the container / var/lib/mysql directory

Docker run-dit-e MYSQL_ROOT_PASSWORD=123456-p 3306 MYSQL_ROOT_PASSWORD=123456 3306-v / home/database:/var/lib/mysql mysql:5.7

Docker ps view container

We now run two containers, one is an Alpine container with nginx and php installed, and the other is a mysql5.7 container

Enter the mysql container

Docker exec-it c8c85af64822 sh

Log in and create a wordpress database

# Log in to mysql-u root-p # with root user to create wordpress database mysql > CREATE DATABASE wordpress; to run wordpress blog

Now that the php website environment and mysql database are ready, let's go back to Alpine's ssh terminal and download a wordpress website program in the container.

# enter the website directory cd / home/www/# to download wordpresswget https://wordpress.org/latest.tar.gz# and extract tar zxvf latest.tar.gz# to copy the files in the wordpress directory to the www directory cp-ri / home/www/wordpress/* / home/www/# set 777 permissions chmod-R 777 / home/www/

Visit http://192.168.43.122:8080 in the browser and you can see the wordpres page

Fill in the database information

Installation completed, wordpress normal use!

This is the end of the content of "Docker Application case Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report