Skip to content

Commit e1b88b6

Browse files
committed
First initiation, setting up all necessary files to run up a Docker container.
1 parent 863d991 commit e1b88b6

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

.env

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Set database credential
2+
DB_HOST=127.0.0.1
3+
DB_NAME=www
4+
DB_USER=wwwadmin
5+
DB_PASSWORD=wwwpassword
6+
7+
# Set WordPress environments
8+
WP_VERSION=
9+
WP_DEBUG=true
10+
WP_TITLE=WPonWhales: A Bubble
11+
WP_BASE_URL=http://127.0.0.1
12+
13+
# Set admin account
14+
WP_ADMIN_USER=admin
15+
WP_ADMIN_PASSWORD=password
16+
WP_ADMIN_EMAIL=[email protected]
17+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/html

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM php:7.3-apache
2+
3+
LABEL maintainer="Rei Nuttanon"
4+
5+
ARG DB_HOST
6+
ARG DB_NAME
7+
ARG DB_USER
8+
ARG DB_PASSWORD
9+
10+
ENV APACHE_RUN_USER www-data
11+
ENV APACHE_RUN_GROUP www-data
12+
ENV APACHE_LOG_DIR /var/log/apache2
13+
ENV APACHE_PID_FILE /var/run/apache2.pid
14+
ENV APACHE_RUN_DIR /var/run/apache2
15+
ENV APACHE_LOCK_DIR /var/lock/apache2
16+
17+
RUN echo "mysql-server mysql-server/root_password password $DB_PASSWORD" | debconf-set-selections
18+
RUN echo "mysql-server mysql-server/root_password_again password $DB_PASSWORD" | debconf-set-selections
19+
20+
RUN apt-get update && apt-get install -y --force-yes \
21+
mysql-server \
22+
&& rm -rf /var/lib/apt
23+
24+
RUN docker-php-ext-install mysqli
25+
26+
# Add INSTALL.sh.
27+
COPY ./bin/install /var/www/bin/install
28+
RUN chmod +x /var/www/bin/install
29+
30+
# Download WP-CLI
31+
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
32+
RUN chmod +x wp-cli.phar
33+
RUN mv wp-cli.phar /usr/local/bin/wp
34+
35+
# Apache configuration
36+
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
37+
RUN a2enmod rewrite
38+
RUN chown www-data:www-data -R /var/www/
39+
40+
EXPOSE 80

bin/install

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
service mysql start
2+
mysql -u root -proot -e "CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASSWORD'; GRANT ALL PRIVILEGES ON * . * TO '$DB_USER'@'localhost';";
3+
mysqladmin -h localhost -P 3306 -u $DB_USER -p$DB_PASSWORD create $DB_NAME --force 2> /dev/null;
4+
5+
# ..
6+
# 1. Download WordPress.
7+
if [ -z $WP_VERSION ]; then
8+
wp core download --allow-root
9+
else
10+
wp core download --version=$WP_VERSION --allow-root
11+
fi
12+
13+
14+
# ..
15+
# 2. Config WordPress.
16+
if [ "$WP_DEBUG" = true ] ; then
17+
wp core config \
18+
--allow-root \
19+
--skip-check \
20+
--dbhost=$DB_HOST \
21+
--dbname=$DB_NAME \
22+
--dbuser=$DB_USER \
23+
--dbpass=$DB_PASSWORD \
24+
--extra-php <<PHP
25+
define( 'WP_DEBUG', true );
26+
define( 'WP_DEBUG_LOG', true );
27+
define( 'FS_METHOD', 'direct' );
28+
PHP
29+
else
30+
wp core config \
31+
--allow-root \
32+
--skip-check \
33+
--dbhost=$DB_HOST \
34+
--dbname=$DB_NAME \
35+
--dbuser=$DB_USER \
36+
--dbpass=$DB_PASSWORD
37+
fi
38+
39+
40+
# ..
41+
# 3. Install WordPress
42+
wp core install \
43+
--allow-root \
44+
--url=$WP_BASE_URL \
45+
--title="$WP_TITLE" \
46+
--admin_user=$WP_ADMIN_USER \
47+
--admin_password=$WP_ADMIN_PASSWORD \
48+
--admin_email="$WP_ADMIN_EMAIL"
49+
50+
51+
chown -R www-data:www-data /var/www/
52+
apache2 -D FOREGROUND

docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3'
2+
services:
3+
www:
4+
build:
5+
context: .
6+
args:
7+
- DB_HOST=$DB_HOST
8+
- DB_NAME=$DB_NAME
9+
- DB_USER=$DB_USER
10+
- DB_PASSWORD=$DB_PASSWORD
11+
image: wowbubble:0.1
12+
ports:
13+
- "80:80"
14+
volumes:
15+
- ./html:/var/www/html
16+
command: ["/var/www/bin/install"]
17+
environment:
18+
- DB_HOST
19+
- DB_NAME
20+
- DB_USER
21+
- DB_PASSWORD
22+
- WP_VERSION
23+
- WP_DEBUG
24+
- WP_TITLE
25+
- WP_BASE_URL
26+
- WP_ADMIN_USER
27+
- WP_ADMIN_PASSWORD
28+
- WP_ADMIN_EMAIL

0 commit comments

Comments
 (0)