Docker Apache MySQL: Difference between revisions

From Corat Coret
mNo edit summary
Line 120: Line 120:
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.7/install.sh | bash
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.7/install.sh | bash


ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV NODE_PATH $NVM_DIR/$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH
ENV PATH $NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH



Revision as of 11:15, 19 June 2024

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

Jika ingin menambahkan nodejs / npm

ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

ENV NVM_VERSION v0.39.7
ENV NODE_VERSION v18.17.0
ENV NVM_DIR /usr/local/nvm
RUN mkdir -p $NVM_DIR
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.7/install.sh | bash

ENV NODE_PATH $NVM_DIR/$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH

RUN echo "source $NVM_DIR/nvm.sh && \
    nvm install $NODE_VERSION && \
    nvm alias default $NODE_VERSION && \
    nvm use default" | bash