当前位置: 首页 > article >正文

dockerfile2.0

dockerfile实现lnmp

nginx centos7
mysql centos7
php centos7

自定义镜像来实现整个架构

cd /opt

mkdir nginx mysql php

cd nginx
拖入nginx和wordpress

vim Dockerfile

在这里插入图片描述

在这里插入图片描述

vim nginx.conf

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;
        }
}
}
docker build -t nginx:lnmp .

docker images

df -h

docker create  --subnet=172.111.0.0/16 mynetwork

docker run -itd --name nginx -p 80:80  --cpu quota 20000  -m 512m  -v /opt/nginx1: /usr/local/nginx/logs --net mynetwork --ip 172.111.0.10 nginx:lnmp

mysql:

vim Dockerfile

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
#安装mysql的依赖环境
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
#修改mysql目录的名称
COPY my.cnf /etc/my.cnf
EXPOSE 3306
#暴露mysql的端口,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
#主要是因为容器内部无法使用systemctl命令来对容器进行操作,只能添加环境
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"]
#因为就在工作目录下,工作目录包含mysql启动二进制脚本文件

vim my.cnf

[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
docker build -t mysql:lnmp .

docker run -itd --name mysql -p 3306:3306 -privileged -v /opt/mysql1 : /opt/mysql --net mynetwork --ip 172.111.0.20 --cpu-quota 50000 -m 2g mysql:lnmp
mysql -u -p

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)
 
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE USER 'wordpress'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

php:

cd php

vim Dockerfile

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
ENTRYPOINT ["/usr/local/php/sbin/php-fpm","-"]
docker build -t php:lnmp .

docker run -itd --name php -p 9000:9000 --volumes-from nginx --volumes-from mysql  --net mynetwork --ip 172.111.0.30 --cpu-quota 50000 -m 1g php:lnmp

docker ps

打开浏览器访问192.168.31.10/workpress即完成所有内容

作业:实现elk+filebeat的容器部署

es:两个

logstash:部署一个

kibana:作为前端

dockerfile自定义镜像

filebeat ················不需要用docker


http://www.kler.cn/a/503950.html

相关文章:

  • WINFORM - DevExpress -> gridcontrol ---->控件(ColumnEdit控件)
  • Windows service运行Django项目
  • Vue 3前端与Python(Django)后端接口简单示例
  • 计算机网络八股文学习笔记
  • 图解Git——分支开发工作流《Pro Git》
  • SQL 详解数据库
  • 61_Redis服务器端优化
  • Android 中mk文件语法浅析
  • 鸿蒙打包发布
  • Windows CMD 常用命令
  • Docker Compose 教程
  • 【论文笔记】SmileSplat:稀疏视角+pose-free+泛化
  • 【专题】2025年节日营销趋势洞察报告汇总PDF洞察(附原数据表)
  • Idea+docker通过dockerFile方式往华为云发布项目
  • 主流消息队列(MQ)对比分析
  • ros2笔记-7.1 机器人导航介绍
  • ISP各模块功能介绍
  • 【Vue】let、const、var的区别、适用场景
  • Java中网络编程的学习
  • 深度解析 pytest 参数化与 --count 执行顺序的奥秘
  • 零碎的知识点(七):线性二次调节器(LQR)是什么?
  • IIS安全配置基线
  • 自动连接校园网wifi脚本实践(自动网页认证)
  • 水下通信:特点、主要应用与典型系统
  • 数据仓库基础常见面试题
  • 【算法】回溯法