One click deployment docker CE container lnmp running wordpress

Keywords: Docker Nginx PHP yum

Preface

During this period of time, I concentrated on studying docker, wanted to write something out, and finally wrote a wordpress running in container.
I packed the image and script, and hung them on my server. If you have time, you can download them to play.

docker

I put the packed files on the server. The download speed may be a little slow.

wget ftp://www.seeit.life/pub/lnmp.tar #This is the image package and the startup script
wget ftp://www.seeit.life/pub/startlnmp.sh #This is to decompress the image and start the startup script in the tar package

The whole process of automation Oh, only the last you have to set your own account password.
as long as

bash startlnmp.sh

dockerfile

Next, I put out the dockerfile file, and what other files are available.

[ root@node3 ~/lnmp ]# ls
fpm  mariadb  nginx
[ root@node3 ~/lnmp ]# cd fpm/
[ root@node3 ~/lnmp/fpm ]# ls
CentOS-Base.repo  Dockerfile  epel.repo

In Centos-Base.repo epel.repo file, I will change the address to my own private warehouse faster.
It doesn't matter if you don't change it.

[ root@node3 ~/lnmp/fpm ]# cat Dockerfile 
# php-fpm server
FROM centos:7.4.1708

MAINTAINER "Rootygl <rootygl@163.com>"

COPY CentOS-Base.repo \ 
epel.repo /etc/yum.repos.d/

RUN yum -y install php-fpm php-mbstring php-mysql; \
    yum clean all; \
    rm -rf /var/cache/yum/*;

VOLUME "/webapp/wordpress"

CMD ["/usr/sbin/php-fpm","--nodaemonize"]
[ root@node3 ~/lnmp/mariadb ]# ls
CentOS-Base.repo  Dockerfile  epel.repo  start-db.sh

Dockerfile file of mariadb

[ root@node3 ~/lnmp/mariadb ]# cat Dockerfile 
# Mariadb-server
FROM centos:7.4.1708

MAINTAINER "Rootygl <rootygl@163.com>"

COPY CentOS-Base.repo \ 
epel.repo /etc/yum.repos.d/

COPY start-db.sh /usr/bin/

RUN yum -y install mariadb-server; \ 
    yum clean all; \ 
    rm -rf /var/cache/yum/*;

VOLUME "/var/lib/mysql"

ENTRYPOINT ["/bin/bash","-c","/usr/bin/start-db.sh"]
[ root@node3 ~/lnmp/mariadb ]# cat start-db.sh 
#!/bin/bash
#
/usr/libexec/mariadb-prepare-db-dir

/usr/bin/mysqld_safe --basedir=/usr 

Because I need to modify the configuration file of nginx.conf and bring it to port 9000, I'd better write it outside and directly overwrite the one inside.

[ root@node3 ~/lnmp/nginx ]# ls
Dockerfile  nginx.conf
[ root@node3 ~/lnmp/nginx ]# cat Dockerfile 
#nginx server

FROM centos:7.4.1708

MAINTAINER "Rootygl <rootygl@163.com>" 

ENV nginx_version 1.12.2
ENV nginx_url http://nginx.org/download/nginx-${nginx_version}.tar.gz

WORKDIR "/usr/local/src/"

EXPOSE 80/tcp

VOLUME "/webapp/wordpress" 

ADD ${nginx_url} /usr/local/src/


RUN tar xf nginx-${nginx_version}.tar.gz && yum -y install gcc pcre-devel openssl-devel make && yum clean all && rm -rf /var/cache/yum/* \ 
    && cd nginx-${nginx_version} && ./configure && make && make install 

COPY nginx.conf /usr/local/nginx/conf/
CMD ["/usr/local/nginx/sbin/nginx","-g","daemon off;"]
[ root@node3 ~/lnmp/nginx ]# cat nginx.conf 

#user  nobody;
worker_processes  auto;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  5;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /webapp/wordpress;
            index  index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /webapp/wordpress;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

I didn't use the docker compose orchestration container to write yam files. I was too simple to write, so I integrated it into the startup script.

[ root@localhost ~/lnmp ]# ls
docker-lnmp.sh  fpmv1.0.tar  mariadbv1.0.tar  nginxv1.0.tar  wordpress-4.7.4-zh_CN.tar.gz

The three images exported by docker are packed with wordpress, and the initialization script is started.

[ root@localhost ~/lnmp ]# cat docker-lnmp.sh 
#!/bin/bash

#nginx php-fpm mariadb in container
#MAINTAINER "Rootygl <rootygl@163.com>"


yum install -y wget > /dev/null 

wget https://download.docker.com/linux/centos/docker-ce.repo

mv docker-ce.repo /etc/yum.repos.d/

yum clean all && yum repolist all > /dev/null

yum -y install docker-ce 

mkdir -p /etc/docker

tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://us67o6c8.mirror.aliyuncs.com"]
}
EOF

systemctl restart docker 

#wget 

docker load -i fpmv1.0.tar 
docker load -i nginxv1.0.tar 
docker load -i mariadbv1.0.tar 

docker run --name n1 -P -p80:80 -d nginx:v1.0
docker run --name fpm1 -d --volumes-from n1 --net container:n1 fpm:v1.0
docker run --name db1 --net container:fpm1 -d mariadb:v1.0

nginxworkdir=`docker inspect -f {{.Mounts}} n1 | cut -d " " -f 3`
mariadbworkdir=`docker inspect -f {{.Mounts}} db1 | cut -d " " -f 3`
tar xf wordpress-4.7.4-zh_CN.tar.gz 

mv wordpress/* $nginxworkdir

mkdir $mariadbworkdir/wordpress/

chown -R 27:27 $mariadbworkdir/wordpress/

cp $nginxworkdir/wp-config-sample.php $nginxworkdir/wp-config.php
sed -i s/database_name_here/wordpress/ $nginxworkdir/wp-config.php
sed -i s/username_here/root/ $nginxworkdir/wp-config.php
sed -i s/password_here// $nginxworkdir/wp-config.php
sed -i s/'localhost'/'127.0.0.1'/ $nginxworkdir/wp-config.php


echo 'Database name:  wordpress'
echo 'user name:    root'
echo 'Password:      (empty)'
echo 'Database host:127.0.0.1' 

Last

Basically everything is here.
docker container technology can greatly reduce a lot of repetitive work,
Create once, run everywhere. Flexible utilization of resources

Posted by mrdonrule on Mon, 04 May 2020 18:24:35 -0700