dockerfile实现lnmp

dockerfile实现lnmp

  • 配置
  • Nginx
    • [vim Dockerfile](#vim Dockerfile)
    • [vim nginx.conf](#vim nginx.conf)
  • mysql
    • [vim Dockerfile](#vim Dockerfile)
    • [vim my.cnf](#vim my.cnf)
  • php
    • [vim Dockerfile](#vim Dockerfile)

配置

centos7为基础镜像

lnmp

  • n:nginx 172.111.0.10
  • m:mysql 172.111.0.20
  • p:php 172.111.0.30

Nginx

csharp 复制代码
root@u7:/opt/nginx# ls
Dockerfile  nginx.conf  wordpress-6.4.2-zh_CN.tar.gz  nginx-1.22.0.tar.gz

vim Dockerfile

csharp 复制代码
FROM centos:7
#定义基础镜像
MAINTAINER "this is nginx image(lnmp)"
RUN rm -rf /etc/yum.repos.d/* && \
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
    yum clean all && \
    yum makecache
#配置centos的yum源
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
ADD nginx-1.22.0.tar.gz /usr/local/src/
#作用就是解压
RUN useradd -M -s /sbin/nologin nginx
WORKDIR /usr/local/src/nginx-1.22.0
#指向到nginx的源吗目录,直接开始配置,编译和安装
RUN ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module && make -j 4 && make install
#安装nginx
ENV PATH /usr/local/nginx/sbin:$PATH
#设置环境变量
COPY nginx.conf /usr/local/nginx/conf/
ADD wordpress-6.4.2-zh_CN.tar.gz /usr/local/nginx/html
RUN chmod 777 -R /usr/local/nginx/html
EXPOSE 80
VOLUME ["/usr/local/nginx/html/"]
CMD ["nginx","-g","daemon off;"]

vim nginx.conf

csharp 复制代码
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        charset utf-8;
        location / {
            root   html;
            index  index.html index.php;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   172.111.0.30:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }
}
}

mysql

csharp 复制代码
root@u01:/opt/mysql# ls
Dockerfile  my.cnf  mysql-8.0.30-el7-x86_64.tar.gz

vim Dockerfile

csharp 复制代码
FROM centos:7
RUN rm -rf /etc/yum.repos.d/* && \
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
    yum clean all && \
    yum makecache
RUN yum -y install libaio numactl-libs pcre-devel zlib-devel gcc gcc-c++ make
RUN useradd -M -s /sbin/nologin mysql
ADD mysql-8.0.30-el7-x86_64.tar.gz /usr/local
RUN mv /usr/local/mysql-8.0.30-el7-x86_64 /usr/local/mysql
COPY my.cnf /etc/my.cnf
EXPOSE 3306
RUN chown -R mysql:mysql /usr/local/mysql && chown mysql:mysql /etc/my.cnf
ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
WORKDIR /usr/local/mysql/bin/
RUN ./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
VOLUME ["/usr/local/mysql"]
ENTRYPOINT ["./mysqld"]

vim my.cnf

csharp 复制代码
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

php

csharp 复制代码
root@u01:/opt/php# ls
Dockerfile  php-8.1.27.tar.gz  php-fpm.conf  php.ini  www.conf

vim Dockerfile

csharp 复制代码
FROM centos:7
RUN rm -rf /etc/yum.repos.d/* && \
    curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
    yum clean all && \
    yum makecache
RUN yum -y install epel-release
RUN yum -y install gcc gcc-c++ make \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel \
oniguruma-devel \
sqlite-devel
ADD php-8.1.27.tar.gz /usr/local/src/
WORKDIR /usr/local/src/php-8.1.27
RUN ./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-pdo-mysql \
--with-openssl \
--with-sqlite-devel \
--with-oniguruma-devel \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip && make -j 4 && make install
ENV PATH /usr/local/php/bin:/usr/local/php/sbin:$PATH
COPY php.ini /usr/local/php/lib/
COPY php-fpm.conf /usr/local/php/etc/
COPY www.conf /usr/local/php/etc/php-fpm.d/
EXPOSE 9000
相关推荐
sauTCc6 小时前
Docker初探
docker
宁zz6 小时前
乌班图安装jenkins
运维·jenkins
云上艺旅6 小时前
K8S学习之基础七十四:部署在线书店bookinfo
学习·云原生·容器·kubernetes
c无序6 小时前
【Docker-7】Docker是什么+Docker版本+Docker架构+Docker生态
docker·容器·架构
FixBug_Nick6 小时前
使用Docker安装及使用最新版本的Jenkins
docker·容器·jenkins
大丈夫立于天地间6 小时前
ISIS协议中的数据库同步
运维·网络·信息与通信
rainFFrain7 小时前
单例模式与线程安全
linux·运维·服务器·vscode·单例模式
ghostwritten8 小时前
Run Milvus in Kubernetes with Milvus Operator
容器·kubernetes·milvus
Zero_to_zero12349 小时前
解决docker的ubuntu系统中文乱码问题
ubuntu·docker·容器
@郭小茶9 小时前
docker-compose方式部署docker项目
运维·docker·容器