dockerfile 构建LNMP

dockerfile 创建镜像 LNMP+wordpress

nginx 172.111.0.10 docker-nginx

mysql 172.111.0.20 docker-mysql

php 172.111.0.30 docker-php

dockerfile 构建LNMP_第1张图片

dockerfile 构建LNMP_第2张图片

dockerfile 构建LNMP_第3张图片

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 4 && 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

RUN chmod 777 -R /usr/local/nginx/html

EXPOSE 80

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

CMD ["/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 build -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

mysql:

dockerfile 构建LNMP_第4张图片

dockerfile 构建LNMP_第5张图片

FROM centos:7

RUN yum -y install ncurses ncurses-devel bison cmake pcre-devel zlib-devel gcc gcc-c++ make && 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

-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 4 && 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"]

建立镜像:

docker build -t mysql:lnmp .

建立容器:

docker run -itd --name mysql -p 3036:3036 --privileged -v /opt/mysql1:/opt/mysql --net mynetwork --ip 172.111.0.20 mysql:lnmp

一定要给权限:

进入数据库,打开远程连接权限

create database wordpress;

grant all privileges on wordpress.* to 'wordpress'@'%' identified by '123456';

grant all privileges on . to 'root'@'%' identified by '123456';

flush privileges;

php:

dockerfile 构建LNMP_第6张图片

ROM 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

gcc gcc-c++ make pcre-devel && useradd -M -s /sbin/nologin nginx

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

WORKDIR /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 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","-F"]

建立镜像:

docker build -t mysql:lnmp .

创建容器:

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

dockerfile 构建LNMP_第7张图片

8z(JPQs6W&UO2GnUxH

dockerfile 构建LNMP_第8张图片

你可能感兴趣的:(云计算,docker,容器)