0
点赞
收藏
分享

微信扫一扫

[Docker Practical learning] 08Docker Run Wordpress

王栩的文字 2022-03-18 阅读 66


I will add the previous content as soon as possible in the future.

Today, learn how dockerfile and docker work through the WordPress container.

I will record the following things

  1. WordPress installation and configuration
  2. Dockerfil write
  3. Dockerfil builds the image

let’t try!????‍♂

Preparation before experiment

  1. Replace aliyun image in China to speed up
sudo vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://n6syp70m.mirror.aliyuncs.com"]
}
  1. Restart docker service
sudo service docker restart

commencement of operation

  1. Analyze the environment required for the experiment

    1. Nginx provides access
    2. SSH for easy management
    3. PHP and mysql as dependencies
    4. Finally, install wordpress
  2. China docker image speed up

    1. ​RUN echo "deb http://mirrors.cloud.aliyuncs.com/ubuntu/ trusty main universe" > /etc/apt/sources.list​
    2. I use the online learning environment using image to mirrors.cloud.aliyuncs.com,but in our own device we should use mirrors.aliyun.com.
  3. Create Dockerfile

    1. make a folder and create Dockerfile

      $ mkdir wordpress
      $ cd wordpress
      $ touch Dockerfile
    2. edit the Dockerfile

      vim Dockerfile

      The basic framework of previous studies

      # Version 0.1

      # basic image
      FROM ubuntu:14.04

      # MAINTAINER
      MAINTAINER HANXU2018@HANXU2018.com

      # Command
      RUN echo "deb http://mirrors.cloud.aliyuncs.com/ubuntu/ trusty main universe" > /etc/apt/sources.list
      RUN apt-get -yqq update && apt-get install -yqq supervisor && apt-get clean

      # start command
      CMD ["supervisord"]

      use Supervisord to start

  4. complete Dockerfile

    1. Install dependencies
      1. nginx system service
      2. php and mysql wordpress dependencies
    RUN apt-get -yqq install nginx supervisor wget php5-fpm php5-mysql
    1. Install Wordpress

      1. Create the directory for the installation
        ​RUN mkdir -p /var/www​
      2. download and uzip
      3. ADD http://labfile.oss-cn-hangzhou-internal.aliyuncs.com/courses/498/wordpress-4.4.2.tar.gz /var/www/wordpress-4.4.2.tar.gz
        RUN cd /var/www && tar zxvf wordpress-4.4.2.tar.gz && rm -rf wordpress-4.4.2.tar.gz
        RUN chown -R www-data:www-data /var/www/wordpress
    2. Install SSH

      1. Install dependencies and SSH
        ​RUN apt-get install -y openssh-server openssh-client​
      2. create Run directory
        ​RUN mkdir /var/run/sshd​
      3. Configure password and allow remote login
      4. RUN echo 'root:shiyanlou' | chpasswd
        RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
    3. Install Mysql

      1. config root password and install
      2. RUN echo "mysql-server mysql-server/root_password password shiyanlou" | debconf-set-selections
        RUN echo "mysql-server mysql-server/root_password_again password shiyanlou" | debconf-set-selections
        RUN apt-get install -y mysql-server mysql-client
      3. create database for wordpress
        ​RUN service mysql start && mysql -uroot -pshiyanlou -e "create database wordpress;"​​.
    4. open 80 22 port

      1. 80:web
      2. 22:ssh
      3. ​EXPOSE 80 22​
    5. config Supervisord

      1. ​vim supervisord.conf​​create conf

      2. [supervisord]
        nodaemon=true

        [program:php5-fpm]
        command=/usr/sbin/php5-fpm -c /etc/php5/fpm
        autorstart=true

        [program:mysqld]
        command=/usr/bin/mysqld_safe

        [program:nginx]
        command=/usr/sbin/nginx
        autorstart=true

        [program:ssh]
        command=/usr/sbin/sshd -D
      3. add Suervisord in Dockerfile

        1. ​COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf​
      4. start Supervisord

        1. ​CMD ["/usr/bin/supervisord"]​
    6. config Nginx

      1. like config Supervisord ​​vim nginx-config​
      2. server {
        listen *:80;
        server_name localhost;

        root /var/www/wordpress;
        index index.php;

        location / {
        try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
        }
    7. WordPress config

      1. Use sed add this in Dockerfile
      2. RUN sed -i 's/database_name_here/wordpress/g' /var/www/wordpress/wp-config-sample.php
        RUN sed -i 's/username_here/root/g' /var/www/wordpress/wp-config-sample.php
        RUN sed -i 's/password_here/shiyanlou/g' /var/www/wordpress/wp-config-sample.php
        RUN mv /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
    8. update the config file int Dockerfile

      1. ​COPY nginx-config /etc/nginx/sites-available/default​
  5. docker build

    1. befor build i show the complete Dockerfile
    # Version 0.1
    FROM ubuntu:14.04

    MAINTAINER HANXU2018@HANXU2018.com

    RUN echo "deb http://mirrors.cloud.aliyuncs.com/ubuntu/ trusty main universe" > /etc/apt/sources.list
    RUN apt-get -yqq update
    RUN apt-get -yqq install nginx supervisor wget php5-fpm php5-mysql
    RUN echo "daemon off;" >> /etc/nginx/nginx.conf

    RUN mkdir -p /var/www
    ADD http://labfile.oss-cn-hangzhou-internal.aliyuncs.com/courses/498/wordpress-4.4.2.tar.gz /var/www/wordpress-4.4.2.tar.gz
    RUN cd /var/www && tar zxvf wordpress-4.4.2.tar.gz && rm -rf wordpress-4.4.2.tar.gz
    RUN chown -R www-data:www-data /var/www/wordpress

    RUN mkdir /var/run/sshd
    RUN apt-get install -yqq openssh-server openssh-client
    RUN echo 'root:shiyanlou' | chpasswd
    RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config

    RUN echo "mysql-server mysql-server/root_password password shiyanlou" | debconf-set-selections
    RUN echo "mysql-server mysql-server/root_password_again password shiyanlou" | debconf-set-selections
    RUN apt-get install -yqq mysql-server mysql-client

    EXPOSE 80 22

    COPY nginx-config /etc/nginx/sites-available/default
    COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
    RUN service mysql start && mysql -uroot -pshiyanlou -e "create database wordpress;"
    RUN sed -i 's/database_name_here/wordpress/g' /var/www/wordpress/wp-config-sample.php
    RUN sed -i 's/username_here/root/g' /var/www/wordpress/wp-config-sample.php
    RUN sed -i 's/password_here/shiyanlou/g' /var/www/wordpress/wp-config-sample.php
    RUN mv /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

    CMD ["/usr/bin/supervisord"]
    1. make sure you have Dockerfile nginx-config and supervisord.conf three fils
    2. docker build
      1. ​docker build -t wordpress:0.2 /home/shiyanlou/wordpress/​
  6. ​docker images​​can see the images we build just now.

  7. docker run for test

    1. ​docker run -d -p 80:80 --name wordpress wordpress:0.2​
    2. ​docker container ls​​can see the container we run
    3. vist the website 127.0.0.1/wp-admin/install.php on the browser. if success we will see the install pages.

summary

  1. WordPress installation and configuration
  2. Dockerfil write
  3. Dockerfil builds the image
    With the help of the learning website, my progress is very fast,This blog was also written with the help of a tutorial.Writing a blog felt like a lot of work, but I stuck with it.
    My basic knowledge is still unfamiliar, so it will be difficult to do the experiment.
    I will try to practice the basics as much as possible.
    If you have any questions, please contact me.

contact ????

My github is ​​@HANXU2018​​

✉️ google email h1076998404@Gmial.com

????QQ mailbox can get my reply faster

thanks

2020/5/19

????????????



举报

相关推荐

0 条评论