Page cover

Codeigniter

Dockerize Codeigniter Application

Menyiapkan File Docker

Siapkan beberapa file docker yang diperlukan

  • nginx.conf: file konfigurasi dari nginx

  • Dockerfile: berisi file konfigurasi dari docker

  • .dockerignore: list file dan directory yang diabaikan

  • docker-compose.yml: untuk mempermudah menjalankan container

nginx.conf

Buat directory .config terlebih dahulu, kemudian buat file nginx.conf

nginx.conf
server {
    listen 5000;
    server_name localhost;

    location / {
        root /usr/share/nginx/html;
        index index.html;
        try_files $uri $uri/ /index.html;
    }
}

Dockerfile

Pada directory utama, buat file Dockerfile

Dockerfile
FROM php:7.4-fpm
WORKDIR /var/www/html
COPY . /var/www/html
RUN docker-php-ext-install mysqli pdo_mysql
RUN chown -R www-data:www-data /var/www/html && \
    chmod -R 755 /var/www/html && \
    chmod -R 777 /var/www/html/application/cache && \
    chmod -R 777 /var/www/html/application/logs
    
EXPOSE 9000
RUN apt-get update && \
    apt-get install -y \
        nginx \
        nano
        
COPY nginx.conf /etc/nginx/sites-available/default
CMD service nginx start && php-fpm

docker-compose.yml

Isi file docker-compose.yml

docker-compose.yml
version: '3'
services:
  webapp:
    build: .
    image: my-ci-app-image
    container_name: my-ci-app-image
    ports:
      - "5000:5000"

.dockerignore

Isi file .dockerignore

.dockerignore
.git
.gitignore
.dockerignore
Dockerfile
docker-compose.yml

Menjalankan Container

Build image dan jalankan container

docker compose up -d --build

Seharusnya aplikasi sudah bisa berjalan, buka browser dan akses IP server dengan port 5000 (http://127.0.0.1:5000). Untuk menggunakan port lain, ganti setiap port pada file nginx.conf, Dockerfile, dan docker-compose.yml

Last updated