容器第一天学习之-docker之Dockerfile构建LNMP平台

 

dockerfile之nginx

 

dockerfile-nginx文件

FROM centos:7
MAINTAINER Attitude
RUN yum -y install wget &&  cd /etc/yum.repos.d/ && mv CentOS-Base.repo CentOS-Base.repo.J && wget http://mirrors.163.com/.help/CentOS7-Base-163.repo && mv CentOS7-Base-163.repo CentOS-Base.repo && yum makecache
RUN yum -y install unzip epel-release gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* && yum clean all && rm -rf /var/cache/yum/*

COPY nginx-1.14.0.tar.gz /

RUN cd / && tar zxf nginx-1.14.0.tar.gz && cd nginx-1.14.0/ && ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module && make -j 4 && make install && rm -rf /usr/local/nginx/html/* && echo "ok" >> /usr/local/nginx/html/status.html cd / && rm -rf nginx*
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/nginx/sbin
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
WORKDIR /usr/local/nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

 

nginx.conf

user                 nobody;
worker_processes     4;
worker_rlimit_nofile 65535;
error_log  logs/error.log  notice;

pid        /var/run/nginx.pid;
events {
    use epoll;
    worker_connections  4096;
}
http {

    include       mime.types;
    default_type  application/octet-stream;

    log_format  main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log off;
    keepalive_timeout  65;

    client_max_body_size         64m;
    server {
        listen 80;
        server_name www.ctnrs.com;
        index index.php index.html;

        access_log logs/www.ctnrs.com_access.log;
        error_log logs/www.ctnrs.com_error.log;

        # location ~ .*\.(js|css|html|png|gif|jpg|jpeg)$ {
        location / {
            root /www;
        }
        location ~* \.php$ {
            root /wwwroot;
            fastcgi_pass lnmp_php:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
}

 

 

 

dockerfile之php

 

dockerfile-php

FROM centos:7
MAINTAINER Attitude
RUN yum -y install wget &&  cd /etc/yum.repos.d/ && mv CentOS-Base.repo CentOS-Base.repo.J && wget http://mirrors.163.com/.help/CentOS7-Base-163.repo && mv CentOS7-Base-163.repo CentOS-Base.repo && yum makecache
RUN yum install epel-release -y && yum install -y gcc gcc-c++ make gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel libmcrypt-devel libxslt-devel libtidy-devel autoconf iproute net-tools telnet wget curl && yum clean all && rm -rf /var/cache/yum/*

COPY php-5.6.36.tar.gz /

RUN cd / && tar zxf php-5.6.36.tar.gz && cd php-5.6.36 && ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-opcache --with-mysql --with-mysqli --with-pdo-mysql --with-openssl --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-mcrypt --enable-hash && make -j 4 && make install && cp php.ini-production /usr/local/php/etc/php.ini && cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf && sed -i "90a \daemonize = no" /usr/local/php/etc/php-fpm.conf && mkdir /usr/local/php/log &&  cd / && rm -rf php* && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/php/sbin
COPY php.ini /usr/local/php/etc/
COPY php-fpm.conf /usr/local/php/etc/
WORKDIR /usr/local/php
EXPOSE 9000
CMD ["php-fpm"]

 

php-fpm.conf 

[global]
pid = /var/run/php-fpm.pid
error_log = /usr/local/php/log/php-fpm.log
log_level = warning
emergency_restart_interval = 24h
process_control_timeout = 5s
daemonize = no 
rlimit_files = 10240
[www]
user = nobody
group = nobody
listen = 0.0.0.0:9000
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 200
pm.start_servers = 50
pm.min_spare_servers = 50
pm.max_spare_servers = 100
pm.max_requests = 51200
pm.status_path = /status
slowlog = log/$pool.log.slow
request_slowlog_timeout = 10
request_terminate_timeout = 600 
rlimit_files = 10240

 

php.ini

[PHP]
engine = On
short_open_tag = Off
asp_tags = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 100M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 100M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
date.timezone = Asia/Shanghai
[filter]
[iconv]
[intl]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQL]
mysql.allow_local_infile = On
mysql.allow_persistent = On
mysql.cache_size = 2000
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
[MSSQL]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatibility_mode = Off
mssql.secure_connection = Off
[Assertion]
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]
[opcache]
opcache.enable=1
opcache.enable_cli=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=20000
opcache.use_cwd=1
opcache.validate_timestamps=1
opcache.revalidate_freq=0
[curl]
[openssl]

 

 

 

关于mysql,我采用的是官方的镜像,因为在制作mysql镜像时,老是出错,系统空间不足,反应超时,连接出错等,奇葩错误

 

 

 

生成镜像

 

nginx镜像

docker build -t nginx:v1 -f dockerfile-nginx .

 

php镜像

docker build -t php:v1 -f dockerfile-php .

 

 

 

构建wordpress博客实例

 

创建容器网络

docker network create lnmp

 

创建MysqL容器

docker run -d --name lnmp_mysql --net lnmp --mount src=mysql-vol,dst=/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress mysql:5.7 --character-set-server=utf8

 

创建PHP容器

docker run -d --name lnmp_php --net lnmp --mount src=wwwroot,dst=/www php:v1

 

创建nginx容器

docker run -d --name lnmp_nginx --net lnmp -p 88:80 --mount type=bind,src=$(pwd)/nginx.conf,dst=/usr/local/nginx/conf/nginx.conf --mount src=wwwroot,dst=/www nginx:v1

 

 

查看www数据卷详细信息

docker volume inspect www

[
    {
        "CreatedAt": "2019-03-17T05:38:32+08:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/www/_data",
        "Name": "www",
        "Options": null,
        "Scope": "local"
    }
]

 

进行www镜像目录

cd /var/lib/docker/volumes/www/_data

 

下载wordpress博客为例

wget https://cn.wordpress.org/latest-zh_CN.tar.gz

 

解压并部署

tar -zxf latest-zh_CN.tar.gz

rm -rf latest-zh_CN.tar.gz

mv wordpress/* .

 

进行wordpress的web界面

本机IP加:88

 

配置wp-config.php文件

按照说明,我们将他界面上的代码,复制后,在www数据卷目录中创建wp-config.php文件

 

 

配置站点信息

 

这样子,一个简单的lnmp环境加wordpress博客平台就完成了

 

 

 

 

 

发表评论:

共有 0 条评论

 Top