-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
82 lines (73 loc) · 3.37 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Step 1 : From image
FROM debian:buster
# Step 2 : Set env
ENV AUTOINDEX on
# Step 3 : Install
RUN apt-get update && apt-get install -y \
wget \
nginx \
php-fpm \
default-mysql-server \
php-mysql
# Step 4 : Config SSL(Self signed Certificate)
RUN openssl req \
-x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/localhost.key \
-out /etc/ssl/certs/localhost.crt \
-subj "/C=KR/ST=Seoul/O=42Seoul/CN=localhost"
# Step 5 : Config Nginx && SSL
RUN cd /etc/nginx/sites-available && \
echo "server {" >> wordpress && \
echo "\tlisten 80;" >> wordpress && \
echo "\tlisten [::]:80;\n" >> wordpress && \
echo "\tlisten 443;" >> wordpress && \
echo "\tlisten [::]:443;\n" >> wordpress && \
echo "\tssl on;" >> wordpress && \
echo "\tssl_certificate_key /etc/ssl/private/localhost.key;" >> wordpress && \
echo "\tssl_certificate /etc/ssl/certs/localhost.crt;\n" >> wordpress && \
echo "\troot /var/www/wordpress;\n" >> wordpress && \
echo "\tindex index.php;\n" >> wordpress && \
echo "\tserver_name localhost;\n" >> wordpress && \
echo '\terror_page 497 https://$host$request_uri;\n' >> wordpress && \
echo "\tlocation / {" >> wordpress && \
echo "\t\tautoindex on;" >> wordpress && \
echo '\t\ttry_files $uri $uri/ =404;' >> wordpress && \
echo "\t}\n" >> wordpress && \
echo "\tlocation ~ \.php$ {" >> wordpress && \
echo "\t\tinclude snippets/fastcgi-php.conf;" >> wordpress && \
echo "\t\tfastcgi_pass unix:/var/run/php/php7.3-fpm.sock;" >> wordpress && \
echo "\t}" >> wordpress && \
echo "}" >> wordpress && \
rm /etc/nginx/sites-enabled/default && \
ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
# Step 6 : Config MySQL
RUN service mysql start && \
echo "CREATE DATABASE wordpress;" | mysql -u root --skip-password && \
echo "GRANT ALL ON wordpress.* TO 'root'@'localhost' WITH GRANT OPTION;" | mysql -u root --skip-password && \
echo "UPDATE mysql.user SET plugin='mysql_native_password' WHERE user='root';" | mysql -u root --skip-password && \
echo "FLUSH PRIVILEGES;" | mysql -u root --skip-password
# Step 7 : Config wordpress
RUN wget -O /tmp/wordpress.tar.gz https://wordpress.org/latest.tar.gz && \
tar -xzvf /tmp/wordpress.tar.gz -C /var/www && \
chown -R www-data.www-data /var/www/wordpress && \
cd /var/www/wordpress && \
mv wp-config-sample.php wp-config.php && \
sed -i "s/database_name_here/wordpress/g" wp-config.php && \
sed -i "s/username_here/root/g" wp-config.php && \
sed -i "s/password_here//g" wp-config.php
# Step 8 : Config phpMyAdmin
RUN cd /var/www/wordpress && \
wget -O /tmp/phpmyadmin.tar.gz https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz && \
tar -xzvf /tmp/phpmyadmin.tar.gz -C /var/www/wordpress && \
mv php* phpmyadmin && \
cd phpmyadmin && \
mv config.sample.inc.php config.inc.php && \
sed -i '/AllowNoPassword/ s/false/true/g' config.inc.php
# Step 9 : Expose port
EXPOSE 80 443
# Step 10 : Run container
CMD sed -i "s/autoindex on/autoindex $AUTOINDEX/g" /etc/nginx/sites-available/wordpress && \
service php7.3-fpm start && \
service mysql start && \
echo "Nginx is running foreground." && \
nginx -g "daemon off;"