Skip to content

Commit 77d88f9

Browse files
committed
add dockerfile , modify docker-compose
1 parent 8406cc0 commit 77d88f9

File tree

3 files changed

+71
-68
lines changed

3 files changed

+71
-68
lines changed

Dockerfile

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Use Dedian as base image
2+
FROM debian:bookworm-slim as base
3+
4+
# Install packages
5+
RUN apt-get update && \
6+
apt-get install -y \
7+
apache2 \
8+
curl \
9+
libapache2-mod-php \
10+
git \
11+
php8.2-mbstring \
12+
php8.2-xml \
13+
php8.2 \
14+
php8.2-mysql \
15+
php8.2-pdo \
16+
unzip \
17+
vim \
18+
wget \
19+
&& apt-get clean \
20+
&& rm -rf /var/lib/apt/lists/*
21+
22+
# Create the 'xfs' user and group
23+
RUN groupadd xfs && \
24+
useradd -r -g xfs -s /bin/bash xfs
25+
26+
27+
# Enable Apache modules
28+
RUN a2enmod php8.2
29+
RUN a2enmod rewrite
30+
31+
# Install Composer
32+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
33+
34+
COPY ./config/composer/composer.json /var/www/html/composer.json
35+
COPY ./config/composer/composer.lock /var/www/html/composer.lock
36+
37+
# Install WordPress CLI
38+
RUN wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
39+
&& chmod +x wp-cli.phar \
40+
&& mv wp-cli.phar /usr/local/bin/wp
41+
42+
# Set up WordPress
43+
WORKDIR /var/www/html
44+
RUN wp core download --allow-root
45+
46+
47+
# Remove the default Apache index.html file
48+
RUN rm /var/www/html/index.html
49+
50+
51+
# Initialize and start Apache service
52+
COPY startupservice.sh /startupservice.sh
53+
RUN chmod +x /startupservice.sh
54+
55+
# Expose ports for Apache and MariaDB
56+
EXPOSE 80
57+
58+
ENTRYPOINT ["/startupservice.sh"]
59+

docker-compose.yml

+6-68
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,25 @@
1-
# https://github.com/docker/compose/issues/4513#issuecomment-281478365
2-
# >> Are we just expected to stay on [Docker Compose file format version 2] if
3-
# >> we want to use docker-compose and not swarm mode?
4-
# >
5-
# > Yes.
6-
#
7-
# https://docs.docker.com/compose/compose-file/compose-file-v2/
81
version: '2.4'
92

103
services:
114

12-
index-composer:
5+
index-wordpress:
136
command: 'true'
14-
container_name: index-composer
7+
container_name: index-wordpress
158
depends_on:
169
- index-wpdb
17-
- index-web
1810
# https://hub.docker.com/_/composer
19-
image: composer
20-
user: xfs
21-
volumes:
22-
- ./config/composer/composer.json:/var/www/html/composer.json
23-
- ./config/composer/composer.lock:/var/www/html/composer.lock
24-
- index-wp-data:/var/www/html
11+
image: my-wordpress-site
2512
working_dir: /var/www/html/
26-
27-
index-phpmyadmin:
28-
container_name: index-phpmyadmin
29-
depends_on:
30-
- index-wpdb
13+
networks:
14+
- index-backend
3115
environment:
3216
MYSQL_ROOT_PASSWORD: root
3317
PMA_HOST: index-wpdb
3418
PMA_PORT: 3306
35-
# https://hub.docker.com/_/phpmyadmin
36-
image: phpmyadmin
37-
networks:
38-
- index-backend
39-
ports:
40-
- '8003:80'
41-
volumes:
42-
# Apache2 web server configuration
43-
- ./config/phpmyadmin-sites-available:/etc/apache2/sites-available:ro
44-
45-
index-web:
46-
container_name: index-web
47-
depends_on:
48-
- index-wpdb
49-
environment:
5019
WORDPRESS_CONFIG_EXTRA: |
5120
# Use dispatch port by default
5221
if ('${CODESPACE_NAME:-}') {
5322
define('WP_HOME', 'https://${CODESPACE_NAME:-}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-}');
54-
define('WP_SITEURL', 'https://${CODESPACE_NAME:-}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-}');
5523
} else {
5624
define('WP_HOME', 'http://localhost:8080');
5725
define('WP_SITEURL', 'http://localhost:8080');
@@ -61,12 +29,6 @@ services:
6129
WORDPRESS_DB_USER: root
6230
WORDPRESS_DB_name: wordpress
6331
WORDPRESS_USER: root
64-
# https://hub.docker.com/_/wordpress
65-
# https://github.com/docker-library/repo-info/blob/master/repos/wordpress/remote/latest.md
66-
# https://github.com/docker-library/repo-info/blob/master/repos/wordpress/local/latest.md
67-
image: wordpress:${WP_VERSION:?err}
68-
networks:
69-
- index-backend
7032
ports:
7133
- '8080:80'
7234
restart: on-failure
@@ -94,31 +56,6 @@ services:
9456
# Migration cache
9557
- ./cache:/var/www/html/cache:ro
9658

97-
index-wpcli:
98-
# continue running until shutdown (this allows docker compose exec which is
99-
# much faster than docker compose run)
100-
# Thank you: https://serverfault.com/a/1084975
101-
command: sh -c 'trap "exit" TERM; while true; do sleep 1; done'
102-
container_name: index-wpcli
103-
depends_on:
104-
- index-wpdb
105-
- index-web
106-
environment:
107-
WORDPRESS_DB_HOST: index-wpdb:3306
108-
WORDPRESS_DB_NAME: wordpress
109-
WORDPRESS_DB_PASSWORD: root
110-
WORDPRESS_DB_USER: root
111-
WORDPRESS_USER: root
112-
# https://hub.docker.com/_/wordpress
113-
image: wordpress:cli
114-
networks:
115-
- index-backend
116-
user: xfs
117-
volumes:
118-
# WordPress
119-
- index-wp-data:/var/www/html
120-
# Migration cache
121-
- ./cache:/var/www/html/cache:ro
12259

12360
index-wpdb:
12461
container_name: index-wpdb
@@ -143,3 +80,4 @@ volumes:
14380
networks:
14481
index-backend:
14582
name: index-backend
83+

startupservice.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
4+
# Start Apache in the foreground
5+
exec apache2ctl -D FOREGROUND
6+

0 commit comments

Comments
 (0)