Docker容器编译LNMP

该博客介绍了如何使用Docker基于centos镜像分别编译安装Nginx、Mysql和PHP,创建LNMP环境。详细步骤包括每个组件的镜像制作,容器的运行以及最终通过container模式网络访问PHP测试页面。
摘要由CSDN通过智能技术生成

一、 项目描述

使用Docker容器基于centos镜像分别制作nginx镜像,mysql镜像和php镜像使用编译安装的方式,最后通过镜像启动成容器时使用container模式网络模式并访问到php测试页面

二、 Nginx镜像制作

//拉取centos镜像
[root@Docker ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   2 months ago   231MB

// 运行centos镜像
[root@localhost ~]# docker run -it --name nginx 5d0da3dc9764 /bin/bash
[root@03ca6bdc0374 /]# 

// 传nginx安装包到容器中
[root@localhost ~]# docker cp /usr/src/nginx-1.20.1.tar.gz 03ca6bdc0374:/usr/src/

// 创建nginx账户
[root@03ca6bdc0374 /]# useradd -r -M -s /sbin/nologin nginx

// 安装依赖包
[root@03ca6bdc0374 /]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make

// 创建nginx日志存放目录
[root@03ca6bdc0374 /]# mkdir -p /var/log/nginx
[root@03ca6bdc0374 /]# chown -R nginx.nginx /var/log/nginx/

// 解压nginx包进行编译安装
[root@03ca6bdc0374 /]# cd /usr/src/
[root@03ca6bdc0374 src]# ls
debug  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

// 设置环境变量
[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 

// 查看监听端口
[root@03ca6bdc0374 nginx-1.20.1]# nginx
[root@03ca6bdc0374 nginx-1.20.1]# ss -antl
State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port Process                                                      
LISTEN 0      128           0.0.0.0:80          0.0.0.0:* 

[root@localhost ~]# curl 172.17.0.2 
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
   
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值