@H_5020@1. 安装 Docker
@H502_0@在我们真正开始之前,我们需要确保在我们的 Linux 机器上已经安装了 Docker。我们使用的主机是 CentOS 7,因此我们用下面的命令使用 yum 管理器安装 docker。
<div class="jb51code">
<pre class="brush:bash;">
@H_5020@1. 安装 Docker
@H_502_0@
<img ="201572995512549.png (684×490)" src="https://files.jb51.cc/file_images/article/201507/201572995512549.png?201562995537" />
<div class="jb51code">
<pre class="brush:plain;">
FROM centos:centos7
MAINTAINER The CentOS Project cloud-ops@centos.org
RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN yum -y install mariadb mariadb-server mariadb-client Nginx PHP-fpm PHP-cli PHP-MysqL PHP-gd PHP-imap PHP-ldap PHP-odbc PHP-pear PHP-xml PHP-xmlrpc PHP-magickwand PHP-magpieRSS PHP-mbstring PHP-mcrypt PHP-mssql PHP-shout PHP-snmp PHP-soap PHP-tidy PHP-apc pwgen python-setuptools curl git tar; yum clean all
ADD ./start.sh /start.sh
ADD ./Nginx-site.conf /Nginx.conf
RUN mv /Nginx.conf /etc/Nginx/Nginx.conf
RUN rm -rf /usr/share/Nginx/html/
RUN /usr/bin/easy_install supervisor
RUN /usr/bin/easy_install supervisor-stdout
ADD ./supervisord.conf /etc/supervisord.conf
RUN echo %sudo ALL=NOPASSWD: ALL >> /etc/sudoers
ADD http://wordpress.org/latest.tar.gz /wordpress.tar.gz
RUN tar xvzf /wordpress.tar.gz
RUN mv /wordpress/ /usr/share/Nginx/html/.
RUN chown -R apache:apache /usr/share/Nginx/
RUN chmod 755 /start.sh
RUN mkdir /var/run/sshd
EXPOSE 80
EXPOSE 22
CMD ["/bin/bash","/start.sh"]
<div class="jb51code">
<pre class="brush:bash;">
check() {
if [ -f /usr/share/nginx/html/wp-config.php ]; then
exit
fi
}
create_user() {
SSH_USERPASS=pwgen -c -n -1 8
useradd -G wheel user
echo user:$SSH_USERPASS | chpasswd
echo ssh user password: $SSH_USERPASS
}
__mysql_config() {
yum -y erase mariadb mariadb-server
rm -rf /var/lib/mysql/ /etc/my.cnf
yum -y install mariadb mariadb-server
mysql_install_db
chown -R mysql:mysql /var/lib/mysql
/usr/bin/mysqld_safe &
sleep 10
}
__handle_passwords() {
WORDPRESS_DB="wordpress"
MYSQL_PASSWORD=pwgen -c -n -1 12
WORDPRESS_PASSWORD=pwgen -c -n -1 12
echo mysql root password: $MYSQL_PASSWORD
echo wordpress password: $WORDPRESS_PASSWORD
echo $MYSQL_PASSWORD > /MysqL-root-pw.txt
echo $wordpress_PASSWORD > /wordpress-db-pw.txt
sed -e "s/database_name_here/$wordpress_DB/
s/username_here/$wordpress_DB/
s/password_here/$wordpress_PASSWORD/
/'AUTH_KEY'/s/put your unique phrase here/pwgen -c -n -1 65
/
/'SECURE_AUTH_KEY'/s/put your unique phrase here/pwgen -c -n -1 65
/
/'LOGGED_IN_KEY'/s/put your unique phrase here/pwgen -c -n -1 65
/
/'NONCE_KEY'/s/put your unique phrase here/pwgen -c -n -1 65
/
/'AUTH_SALT'/s/put your unique phrase here/pwgen -c -n -1 65
/
/'SECURE_AUTH_SALT'/s/put your unique phrase here/pwgen -c -n -1 65
/
/'LOGGED_IN_SALT'/s/put your unique phrase here/pwgen -c -n -1 65
/
/'NONCE_SALT'/s/put your unique phrase here/pwgen -c -n -1 65
/" /usr/share/Nginx/html/wp-config-sample.PHP > /usr/share/Nginx/html/wp-config.php
}
__httpd_perms() {
chown apache:apache /usr/share/Nginx/html/wp-config.php
}
_startMysqL() {
MysqLadmin -u root password $MysqL_PASSWORD
MysqL -uroot -p$MysqL_PASSWORD -e "CREATE DATABASE wordpress; GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '$wordpress_PASSWORD'; FLUSH PRIVILEGES;"
killall MysqLd
sleep 10
}
__run_supervisor() {
supervisord -n
}
check
create_user
MysqL_config
handle_passwords
__httpd_perms
start_MysqL
run_supervisor
<div class="jb51code">
<pre class="brush:plain;">
user Nginx;
worker_processes 1;
error_log /var/log/Nginx/error.log;
pid /run/Nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/Nginx/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 /var/log/Nginx/access.log main;
sendfile on;
keepalive_timeout 65;
index index.html index.htm index.PHP;
include /etc/Nginx/conf.d/*.conf;
server {
listen 80;
server_name localhost;
root /usr/share/Nginx/html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .PHP$ {
root /usr/share/Nginx/html;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
@H_502_0@
<img ="201572995736091.png (684×490)" src="https://files.jb51.cc/file_images/article/201507/201572995736091.png?201562995747" />
@H_502_0@
<img ="201572995803992.png (684×490)" src="https://files.jb51.cc/file_images/article/201507/201572995803992.png?201562995831" />
@H_502_0@
<img ="201572995845827.png (593×38)" src="https://files.jb51.cc/file_images/article/201507/201572995845827.png?201562995857" />
<div class="jb51code">
<pre class="brush:bash;">