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

How the Docker container compiles LNMP

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "Docker container how to compile LNMP", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Docker container how to compile LNMP" bar!

I. Project description

Use Docker container to make nginx image based on centos image. Mysql image and php image are compiled and installed respectively. Finally, use container mode network mode and access the php test page when launching into a container through the image.

II. Nginx image creation / / pull centos image [root@Docker ~] # docker pull centosUsing default tag: latestlatest: Pulling from library/centosa1d0c7532777: Pull complete Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177Status: Downloaded newer image for centos:latestdocker.io/library/centos:latest [root@localhost ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos latest 5d0da3dc9764 2 months ago 231MB// run centos image [root@localhost ~] # docker run-it-name nginx 5d0da3dc9764 / bin/bash [root@03ca6bdc0374 /] # / transfer nginx installation package to container [root@localhost ~] # docker cp / usr/src/nginx-1.20.1.tar.gz 03ca6bdc0374:/usr/src/// create nginx account [root@03ca6bdc0374 /] # useradd-r-M-s / sbin/nologin nginx// install dependency package [root@03ca6bdc0374 /] # yum-y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make// create nginx date Directory [root@03ca6bdc0374 /] # mkdir-p / var/log/nginx [root@03ca6bdc0374 /] # chown-R nginx.nginx / var/log/nginx/// extract nginx package to compile and install [root@03ca6bdc0374 /] # cd / usr/src/ [root@03ca6bdc0374 src] # lsdebug kernels nginx-1.20.1.tar.gz [root@03ca6bdc0374 src] # tar xf nginx-1.20.1.tar.gz [root@03ca6bdc0374 src] # cd nginx-1.20 .1 [root@03ca6bdc0374 nginx-1.20.1] #. / configure\-prefix=/usr/local/nginx\-- user=nginx\-- group=nginx\-- with-debug\-- with-http_ssl_module\-- with-http_realip_module\-- with-http_image_filter_module\-- with-http_gunzip_module\-- with-http_gzip_static_module\-- with-http_stub_status_module\-- http-log-path=/var/ Log/nginx/access.log\-error-log-path=/var/log/nginx/error.log [root@03ca6bdc0374 nginx-1.20.1] # make & & make install// sets the environment variable [root@03ca6bdc0374 nginx-1.20.1] # echo 'export PATH=/usr/local/nginx/sbin:$PATH' > / etc/profile.d/nginx.sh [root@03ca6bdc0374 nginx-1.20.1] # source / etc/profile.d/nginx.sh / / View Listen on port [root@03ca6bdc0374 nginx-1.20.1] # nginx [root@03ca6bdc0374 nginx-1.20.1] # ss-antlState Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0 root@03ca6bdc0374 nginx-1.20.1 80 0.0.0.0 antlState Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN * [root@localhost ~] # curl 172.17.0.2 Welcome to nginx! Body {width: 35eme; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} Welcome to nginx!

If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

For online documentation and support please refer tonginx.org.Commercial support is available atnginx.com.

Thank you for using nginx.

/ / modify the configuration file [root@03ca6bdc0374 nginx-1.20.1] # vim / usr/local/nginx/conf/nginx.conf.http {include mime.types; default_type application/octet-stream # log_format main'$remote_addr-$remote_user [$time_local] "$request" #'$status $body_bytes_sent "$http_referer" #'"$http_user_agent"$http_x_forwarded_for"; # access_log logs/access.log main; sendfile on; # tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65 # gzip on; server {listen 80; server_name localhost; # charset koi8-r; # access_log logs/host.access.log main; location / {root html; index index.php index.html index.htm; / / add index.php}. Location ~\ .php$ {root / var/www/html; / / php test page directory fastcgi_pass 127.0.0.1 var/www/html; 9000; / / to change to the address of the php server fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $Document_Root$fastcgi_script_name at work Include fastcgi_params;}. Daemon off / / write the last / / reload the configuration file [root@03ca6bdc0374 nginx-1.20.1] # nginx- s reload [root@03ca6bdc0374 nginx-1.20.1] # ss-antlState Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0 reload 80 0.0.0.0usr/local/nginx/sbin/nginx * / create a nginx image [root@localhost ~] # docker commit-a '1826597954 months ago 231MB qq.com'-c' CMD ["/ usr/local/nginx/sbin/nginx"]'- p 03ca6bdc0374 gaofan1225/nginx:v0.1sha256:453bfb1a13ae0aeba38e2e26ebe03e09544aa2ea8b477e45e4fb8aa51fec3e92 [root@localhost ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEgaofan1225/nginx v0.1 453bfb1a13ae 16 seconds ago 575MBcentos latest 5d0da3dc9764 2 months ago 231MB 3, Mysql image creation / / run centos image [root@localhost ~] # docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEgaofan1225/nginx v0.1 453bfb1a13ae 16 seconds ago 575MBcentos latest 5d0da3dc9764 2 months ago 231MB [root@localhost ~] # docker run-it-- name mysql 5d0da3dc9764 / bin/bash [root@3ea39d4dfa8f /] # / transfer mysql installation package to container [root@localhost ~] # docker cp / usr/src/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz 9b6741a9ef22:/usr/src/// installation dependency package [root@9b6741a9ef22 /] # yum-y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs [root@9b6741a9ef22 /] # yum-y install libaio* [root@9b6741a9ef22 /] # yum-y install numactl.x86_64// create mysql user [root@9b6741a9ef22 /] # useradd-r-M-s / Sbin/nologin mysql// unzip installation package [root@9b6741a9ef22 /] # cd / usr/src/ [root@9b6741a9ef22 src] # lsdebug kernels mysql-5.7.34-linux-glibc2.12-x86_ 64.tar.gz [root @ 9b6741a9ef22 src] # tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz-C / usr/local/// make soft links Set the whole school [root@9b6741a9ef22 src] # cd / usr/local/ [root@9b6741a9ef22 local] # lsbin include libexec shareetc lib mysql-5.7.34-linux-glibc2.12-x86_64 srcgames lib64 sbin [root@9b6741a9ef22 local] # ln-sv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql'mysql'-> 'mysql-5.7.34-linux-glibc2.12-x86 _ 64plus'[root@9b6741a9ef22 local] # chown-R mysql.mysql / usr/local/mysql*// sets the environment variable [root@9b6741a9ef22 local] # echo 'export PATH=/usr/local/mysql/bin:$PATH' > / etc/profile.d/mysql.sh [root@9b6741a9ef22 local] # source / etc/profile.d/mysql.sh [root@9b6741a9ef22 local] # echo $PATH/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin : / usr/bin:/sbin:/bin// make header file soft link [root@9b6741a9ef22 local] # ln-s / usr/local/mysql/include / usr/include/mysql// create help document [root@9b6741a9ef22 local] # cat / etc/man_db.conf MANDATORY_MANPATH / usr/local/mysql/man// create library file [root@9b6741a9ef22 local] # cat / etc/ld.so.conf.d/ Mysql.conf/usr/local/mysql/lib [root@9b6741a9ef22 local] # ldconfig// create a data storage directory [root@9b6741a9ef22 local] # mkdir-p / opt/data [root@9b6741a9ef22 local] # chown-R mysql.mysql / opt/data [root@9b6741a9ef22 local] # ls-l / opt/total 0drwxr-xr-x. 2 mysql mysql 6 Dec 4 01:31 data// initialization database [root@9b6741a9ef22 local] # / usr/local/mysql/bin/mysqld-- initialize-insecure-- user=mysql-- datadir=/opt/data/// generation configuration file [root@9b6741a9ef22 local] # cat > / etc/my.cnf

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

Development

Wechat

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

12
Report