基于dockerfile创建镜像

2023-12-14 20:26:25

基于dockerfile创建镜像LNMP+wordpress

nginx 172.111.0.10 ??docker-nginx

mysql 172.111.0.20 ??docker-mysql

php 172.111.0.30 ???docker-php

FROM centos:7

RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make && useradd

?-M -s /sbin/nologin nginx

ADD nginx-1.22.0.tar.gz /usr/local/src/

WORKDIR /usr/local/src/nginx-1.22.0

RUN ./configure \--prefix=/usr/local/nginx \--user=nginx \

--group=nginx \

--with-http_stub_status_module make && -j 16 && make install

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

EXPOSE 80

VOLUME ["/usr/local/nginx/html/"]

ENTRYPOINT ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]

docker network create --subnet=172.111.0.0/16 --opt "com.docker.network.bridge.name"="docker1" mynetwork

docker network ls

docker network rm -f 删除网络

ifconfig

docker bulid -t nginx:lnmp .

docker run -itd --name nginx -p 80:80 -v /opt/nginx:/opt/nginxlogs --net mynetwork --ip 172.111.0.10 nginx:lnmp

docker ps

curl 192.168.233.10(本机IP)

FROM centos:7

useradd -M -s /sbin/nologin mysql

ADD mysql-boost-5.7.20.tar.gz /usr/local/src/

WORKDIR /usr/local/src/mysql-5.7.20/

RUN cmake

cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \-DSYSCONFDIR=/etc \-DSYSTEMD_PID_DIR=/usr/local/mysql \-DDEFAULT_CHARSET=utf8 ?\

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DWITH_BOOST=boost \

-DWITH_SYSTEMD=1 && make -j 16 && make install

COPY my.cnf /etc/my.cnf

EXPOSE 3306

RUN chown -R mysql:mysql /usr/local/mysql/ && chown mysql:mysql /etc/my.cnf

WORKDIR /usr/local/mysql/bin/

RUN ./mysqld \

--initialize-insecure \

--user=mysql \

--basedir=/usr/local/mysql \

--datadir=/usr/local/mysql/data ?&& cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ && systemctl enable mysqld

ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH

VOLUME ["/usr/local/mysql"]

ENTRYPOINT ["/usr/sbin/init.d"]

docker build -t mysql:Inmp .

FROM centos:7

RUN yum -y install gd \

libjpeg libjpeg-devel \

libpng libpng-devel \

freetype freetype-devel \

libxml2 libxml2-devel \

zlib zlib-devel \

curl curl-devel \

openssl openssl-devel && useradd -M -s /sbin/nologin nginx

ADD php-7.1.10.tar.bz2 /usr/local/src/

WROKDIR /usr/local/src/php-7.1.10

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-openssl \

--enable-fpm \

--enable-mbstring \

--enable-xml \

--enable-session \

--enable-ftp \

--enable-pdo \

--enable-tokenizer \

--enable-zip && make -j 16 && 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","-F"]

docker run -itd --name php -p 9000:9000 --volumes-from nginx --volumes-from mysql --net mynetwork --ip 172.111.0.30 php:lnmp

docker exec -it php bash

ps -aux

cd /usr/local/php/

ls

cd ..

ls

cd mysql/

ls

cd ..

cd nginx/

ls

cd workpress/

ls

yaml文件: 是一种标记语言,以竖列的形式展示序列化的数据格式,可读性高类似于json格式。语法简单。

YAML通过缩进来表示数据结构,连续的项目用- 减号来表示yaml文件使用的注意事项

1、大小写敏感

2、通过缩进表示层级关系

3只能用空格缩进不能用tab缩讲

4、可以使用#注释

5、符号字符后面都有一个空格 test:

6、单引号引起来的字符,会被当做普通字符申处理,"#&*”双引号里面是特殊字符,就是本义

YMAL文件基本数据结构

1、声明变量(标量,原子型,单个的,不可再分的值 ?字符串、整数、布尔类型)

name:fkh

age:21

tall:yes

handsome:yes

wan:no

list列表 ??表示有序的元素集合

class:

?- fmh

?- shaoye

?- wushao

(-和a对齐,-后面有个空格)

键值对映射

键值对映射:

Student:

Name: fify

Age: 20

Student1:

Name: ydux

Age: 18

注释:

#test

引用:

Student: &id1

??Name: fhl

??Age: 20

Student1: *id1

用&来定义锚点,用*来进行引用

字符串引号:

Name:hfj

Name:"hfj'

Name:

Name:u

文章来源:https://blog.csdn.net/a91888888/article/details/135000840
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。