[Docker Practical learning] 08 Docker Run Wordpress
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
- WordPress installation and configuration
- Dockerfil write
- Dockerfil builds the image
let't try!πββ
Preparation before experiment
- Replace aliyun image in China to speed up
sudo vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://n6syp70m.mirror.aliyuncs.com"]
}
- Restart docker service
sudo service docker restart
commencement of operation
-
Analyze the environment required for the experiment
- Nginx provides access
- SSH for easy management
- PHP and mysql as dependencies
- Finally, install wordpress
-
China docker image speed up
RUN echo "deb http://mirrors.cloud.aliyuncs.com/ubuntu/ trusty main universe" > /etc/apt/sources.list
- I use the online learning environment using image to mirrors.cloud.aliyuncs.com,but in our own device we should use mirrors.aliyun.com.
-
Create Dockerfile
-
make a folder and create Dockerfile
$ mkdir wordpress $ cd wordpress $ touch Dockerfile
-
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
-
-
complete Dockerfile
- Install dependencies
- nginx system service
- php and mysql wordpress dependencies
RUN apt-get -yqq install nginx supervisor wget php5-fpm php5-mysql
-
Install Wordpress
- Create the directory for the installation
RUN mkdir -p /var/www
- download and uzip
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
- Create the directory for the installation
-
Install SSH
- Install dependencies and SSH
RUN apt-get install -y openssh-server openssh-client
- create Run directory
RUN mkdir /var/run/sshd
- Configure password and allow remote login
RUN echo 'root:shiyanlou' | chpasswd RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
- Install dependencies and SSH
-
Install Mysql
- config root password and install
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
- create database for wordpress
RUN service mysql start && mysql -uroot -pshiyanlou -e "create database wordpress;"
.
- config root password and install
-
open 80 22 port
- 80:web
- 22:ssh
EXPOSE 80 22
-
config Supervisord
-
vim supervisord.conf
create conf -
[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
-
add Suervisord in Dockerfile
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
-
start Supervisord
CMD ["/usr/bin/supervisord"]
-
-
config Nginx
- like config Supervisord
vim nginx-config
-
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; } }
- like config Supervisord
-
WordPress config
- Use sed add this in Dockerfile
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
- Use sed add this in Dockerfile
-
update the config file int Dockerfile
COPY nginx-config /etc/nginx/sites-available/default
- Install dependencies
-
docker build
- 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"]
- make sure you have Dockerfile nginx-config and supervisord.conf three fils
- docker build
docker build -t wordpress:0.2 /home/shiyanlou/wordpress/
-
docker images
can see the images we build just now. -
docker run for test
docker run -d -p 80:80 --name wordpress wordpress:0.2
docker container ls
can see the container we run- vist the website 127.0.0.1/wp-admin/install.php on the browser. if success we will see the install pages.
summary
- WordPress installation and configuration
- Dockerfil write
- 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
My Chinese blog in CSDN site https://hanxu.blog.csdn.net/
βοΈ google email h1076998404@Gmial.com
πͺQQ mailbox can get my reply faster
1076998404@qq.com
thanks
2020/5/19
π€π€π€