使用docker制作nginx,mysql,php容器,实现lamp

nginx

//拉去centos官方镜像
[root@192 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@192 docker]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   2 months ago   231MB

//用centos镜像运行一个容器,用来编译安装nginx
[root@192 ~]# docker run -tid --name nginx centos
ab43656da12089771d1083c4c863705d6f4c22f26fa0dad433c676d43ad7ce59
[root@192 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
ab43656da120   centos    "/bin/bash"   5 seconds ago   Up 5 seconds             nginx
[root@192 ~]# docker exec -it ab43656da120 /bin/bash

//拉去压缩包,解压,下载依赖包
[root@ab43656da120 src]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
[root@ab43656da120 src]# ls
debug  kernels  nginx-1.20.1.tar.gz
[root@ab43656da120 src]# tar xf nginx-1.20.1.tar.gz -C /usr/local/
[root@ab43656da120 src]# cd /usr/local/
[root@ab43656da120 local]# ls
bin  games    lib    libexec       sbin   src
etc  include  lib64  nginx-1.20.1  share
[root@ab43656da120 local]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make

//创建日志存放目录和安装依赖包
[root@ab43656da120 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@ab43656da120 nginx-1.20.1]# make && make install
[root@ab43656da120 ~]# nginx
[root@ab43656da120 ~]# 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@ab43656da120 ~]# 
[root@ab43656da120 ~]# cd /
[root@ab43656da120 /]# vi start.sh
[root@ab43656da120 /]# cat start.sh
#! /bin/sh
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
/bin/bash
[root@ab43656da120 /]# chmod +x start.sh
[root@ab43656da120 /]# cd 
[root@ab43656da120 ~]# cd /usr/local/nginx/conf/
[root@ab43656da120 conf]# vi nginx.conf
       location / {
            root   html;
            index  index.html index.htm index.php;
        }


        location ~ \.php$ {
            root           /var/www/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


//另起终端做容器
[root@192 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
ab43656da120   centos    "/bin/bash"   25 minutes ago   Up 25 minutes             nginx
[root@192 ~]# docker commit -p -c 'CMD ["/bin/bash","/start.sh"]' ab43656da120 yangyonghu/nginx:v0.2
sha256:2a83aeba09ed2b88acff3447a015c9fafb60360b2eecd9522ed9e875ccf3d5fa

测试:

[root@192 ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED              SIZE
yangyonghu/nginx   v0.2      2a83aeba09ed   About a minute ago   550MB
centos             latest    5d0da3dc9764   2 months ago         231MB
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值