ss

Eksperimen WordPress dengan Docker Alpine Linux

Sebelumnya kita membahas artikel Memasang WordPress dengan Docker Compose. Sekarang kita akan kembali mengupasnya dengan bereksperimen menggunakan base Alpine Linux.

Mengapa Base Alpine Linux?

2023 01 10 20 58

Kamu bisa lihat Docker Image berbasis Alpine Linux lebih kecil daripada Docker Image resmi dari pengembangnya. Misalnya MariaDB versi Alpine memiliki ukuran rendah daripada MariaDB versi pengembangnya.

Jika bisa ukuran kecil, mengapa harus besar? Dengan minimalis, kamu menghemat proses pengunduhan, penyimpanan, dan pembangunan Dockerfile.

image 1

Inilah hasil docker stats yang menggunakan image berbasis Alpine Linux. Cukup ringan, bukan?

Memasang WordPress di Docker Alpine Linux

Pertama kita buat folder agar susunan lebih rapi.

$ mkdir wordpress-docker-alpine-linux
$ cd wordpress-docker-alpine-linux

Kita buat berkas “docker-compose.yml

$ vim docker-compose.yml
version: "3"

services:
  nginx:
    image: docker.io/nginx:alpine
    restart: unless-stopped
    ports:
      - ${WORDPRESS_PORT}:8000
      - ${PHPMYADMIN_PORT}:8001
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./wordpress:/var/www/html:ro
      - phpmyadmin:/var/www/phpmyadmin:ro

  wordpress:
    image: docker.io/wordpress:fpm-alpine
    restart: unless-stopped
    depends_on:
      - mariadb
    environment:
      WORDPRESS_DB_HOST: mariadb
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
    volumes:
      - ./wordpress:/var/www/html

  ftp:
    image: docker.io/delfer/alpine-ftp-server
    restart: unless-stopped
    depends_on:
      - wordpress
    environment:
      USERS: "${FTP_USER}|${FTP_PASSWORD}|/var/www/html/wp-content"
      ADDRESS: ftp
    volumes:
      - ./wordpress:/var/www/html

  mariadb:
    image: ghcr.io/linuxserver/mariadb:alpine
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - ./mariadb:/config/databases

  phpmyadmin:
    image: docker.io/phpmyadmin:fpm-alpine
    restart: unless-stopped
    depends_on:
      - mariadb
    volumes:
      - phpmyadmin:/var/www/html
    environment:
      PMA_HOST: mariadb

volumes:
    phpmyadmin:
Code language: JavaScript (javascript)

Buat folder nginx” dan isi dengan konfigurasi “nginx.conf

$ mkdir nginx
$ cd nginx
$ vim nginx.conf
worker_processes 1;

events {
    worker_connections 1024;
}

http {
    include mime.types;

    server {
        listen 8000;

        root /var/www/html/;
        index index.php;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_intercept_errors on;
            fastcgi_pass wordpress:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
        }
    }

    server {
        listen 8001;

        root /var/www/phpmyadmin/;
        index index.php;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_intercept_errors on;
            fastcgi_pass phpmyadmin:9000;
            fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
        }
    }
}Code language: PHP (php)

Buat juga berkas “.env” di folder awal.

$ vim .env
 	WORDPRESS_PORT=8000
	PHPMYADMIN_PORT=8001
	
	MYSQL_DATABASE=wordpress
	MYSQL_USER=wordpress
	MYSQL_PASSWORD=lOb2JfxFnuZGDM1rd3EPwMtjZjPAEka8
	MYSQL_ROOT_PASSWORD=JrrmdCOp0jSy7oXna5TATfEdgY8Z8VKC
	
	FTP_USER=wordpress
	FTP_PASSWORD=8jcbAeCYzhfCplfDyhX6UPO1Stjp9s8t

Setelah itu kita jalankan “docker-compose up -d” di terminal.

$ docker-compose up -d

Artikel Terkait

Leave a Reply

Your email address will not be published. Required fields are marked *