Docker Apache MySQL
Installasi
Menginstall Apache dan MySQL dengan docker
Struktur Direktori
+ docker + +--- database + +--- web + + + default.conf + +--- Dockerfile + docker-compose.yml
File: Dockerfile
FROM php:8.1.2-apache
RUN apt-get update \
&& apt-get install -y \
libfreetype6-dev \
libpng-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libzip-dev \
zip \
git \
default-mysql-client \
&& docker-php-ext-install \
pdo_mysql \
gd \
zip \
&& a2enmod \
rewrite
# Add the user UID:1000, GID:1000, home at /app
RUN groupadd -r app -g 1000 && useradd -u 1000 -r -g app -m -d /app -s /sbin/nologin -c "App user" app && \
chmod 755 /var/www/html
#upload
RUN echo "file_uploads = On\n" \
"memory_limit = 500M\n" \
"upload_max_filesize = 500M\n" \
"post_max_size = 500M\n" \
"max_execution_time = 600\n" \
> /usr/local/etc/php/conf.d/uploads.ini
# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
USER app
WORKDIR /var/www/html
USER root
COPY ./web/default.conf /etc/apache2/sites-enabled/000-default.conf
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
EXPOSE 80
File: docker-compose.yml
version: '3'
services:
web:
environment:
- APACHE_RUN_USER=#1000
build:
context: ./docker
ports:
- 10000:80
volumes:
- ./:/var/www/html
database:
image: mariadb
restart: always
ports:
- 33061:3306
environment:
MYSQL_ROOT_PASSWORD: 123
volumes:
- ./docker/database:/var/lib/mysql
File: default.conf
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Menjalankan
docker compose build
docker compose up -d