如何使用Docker容器化Code​​Igniter项目? [英] How to containerise CodeIgniter project using Docker?

查看:278
本文介绍了如何使用Docker容器化Code​​Igniter项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手,我有一个CodeIgniter项目,到目前为止,我一直在通过本地主机(XAMPP)进行该项目.我现在想使用GCP在Docker上托管我的项目.

I'm very new to Docker and I have a CodeIgniter project that I have been working on via my localhost (XAMPP) up until now. I now want to host my project on Docker using GCP.

任何人都可以提供有关如何编写docker-compose.yml以使用Redis,php,mysql和nginx容器对项目进行容器化的指南吗?另外,我如何安排我的CI项目才能使其正常工作?

Would anyone be able to provide guidance as to how I would write a docker-compose.yml to containerise the project with redis, php, mysql and and nginx containers? Also how would I need my CI project structured for it to work?

推荐答案

我每天都将docker与Codeigniter 4结合使用.这是我的结构,尽管在我的结构中我既不使用redis也不使用nginx.我改用apache.

I use docker with Codeigniter 4 on daily basis. Here's my structure, although in my structure I'm not using neither redis or nginx. I'm using apache instead.

文件夹结构:

.database
.docker
  |php
     |sites-available
       |site.conf
     |Dockerfile
  |custom.ini
  |docker-compose.yml
.git
app
  |app
  |public
  |tests
  |vendor
  |writable
  |.env
  |composer.json
  |composer.lock
  |spark
.gitignore

关于配置文件,这是docker-compose.yml

As for the config files, here's the docker-compose.yml

version: '3'
services:
    web:
        container_name: ci4-web
        build:
            context: ./php
        ports:
            - 80:80
        volumes:
            - ../app:/var/www/html/app/
            - ./custom.ini:/usr/local/etc/php/conf.d/custom.ini
        links:
            - mysql
        depends_on:
          - mysql
    mysql:
        container_name: db-ci4
        image: mysql:latest
        volumes:
            - ./db:/var/lib/mysql
        command: --default-authentication-plugin=mysql_native_password
        ports:
            - 3306:3306
        environment:
            MYSQL_ROOT_PASSWORD: root

Dockerfile

The Dockerfile

FROM php:7.2-apache
RUN apt-get update && \
    apt-get install -y
RUN apt-get install -y curl
RUN apt-get install -y build-essential libssl-dev zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev
RUN apt-get install -y libicu-dev
COPY sites-available/elioter.conf /etc/apache2/sites-enabled/elioter.conf
RUN apt-get update
RUN docker-php-ext-install intl
RUN docker-php-ext-configure intl
RUN docker-php-ext-install mysqli pdo pdo_mysql zip mbstring
RUN a2enmod rewrite
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install gd
RUN service apache2 restart

我的site.conf

my site.conf

<VirtualHost *:80>
    DocumentRoot "/var/www/html/app/public/"
    ServerName ci4.local
    <Directory "/var/www/html/app/public/">
        AllowOverride all
    </Directory>
</VirtualHost>

在我的有关codeigniter 4的youtube系列上,我创建了一个反映此结构的github存储库:

On my youtube series about codeigniter 4 I created a github repo that reflects this structure:

这篇关于如何使用Docker容器化Code​​Igniter项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆