Welcome Guest, Not a member yet? Register   Sign In
Is there a ready-to-use and production-ready Docker container for CodeIgniter?
#1

Hello everyone,

I am looking for a ready-to-use and production-ready Docker container for a CodeIgniter project. I have an application I am developing and would like to know if anyone already has a configured Docker container that can be used for production.

Specifically, I am looking for a container that:

Includes an optimized web server configuration (Apache or Nginx).
Is prepared to handle CodeIgniter dependency management.
Includes security best practices for production environments.
Has examples or documentation that facilitate customization and deployment.
If anyone has a repository or a link to a Docker image they are already using, or any tips on how to configure a suitable container for production, I would greatly appreciate it.

Thank you!
Reply
#2

Docker Image for CodeIgniter4 development
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 05-30-2024, 03:24 AM by Bosborne.)

That container uses Ubuntu and is quite old. I have a Dockerfile that I am getting ready to use in production using the official php image. It is based on Debian Slim and the variant I use has a builtin Apache web server. They keep the image up to date with the latest php patches and OS versions.

I use my Dockerfile with several CI4 projects and may need to pare out extra files not néeded. It could be used along with the appstarter. Were you expecting something using Docker Volumes to mount your code? My current Dockerfile does not automatically run “composer install” but I run it from the container using docker exec.
Reply
#4

(This post was last modified: 05-30-2024, 10:22 PM by ElisBrick.)

Hi there,

You can use the official CodeIgniter Docker repository as a starting point. It provides a Dockerfile and instructions for setting up a CodeIgniter environment with Nginx and PHP-FPM, which is optimized for production.

For an optimized web server configuration, ensure:

Nginx is set up with gzip compression, HTTP/2, and proper caching headers.
PHP-FPM is configured for optimal performance and security.
Security best practices include:

Using a non-root user.
Setting appropriate file permissions.
Disabling unnecessary PHP functions.
For dependency management, use Composer in your Dockerfile to install dependencies.

Here's an example Dockerfile snippet:

FROM php:7.4-fpm

# Install system dependencies
RUN apt-get update && apt-get install -y \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    zip \
    unzip

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \
    docker-php-ext-install gd

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www

# Copy project files
COPY . .

# Install dependencies
RUN composer install

# Expose port
EXPOSE 9000

# Start PHP-FPM
CMD ["php-fpm"]


For detailed customization and deployment, refer to the examples in the repository's documentation.

Hope this helps! and if it resolves your issue, don't forget to give subway sub a try.
Reply
#5

(05-30-2024, 03:24 AM)Bosborne Wrote: That container uses Ubuntu and is quite old.  I have a Dockerfile that I am getting ready to use in production using the official php image.  It is based on Debian Slim and the variant I use has a builtin Apache web server.  They keep the image up to date with the latest php patches and OS versions.

I use my Dockerfile with several CI4 projects and may need to pare out extra files not néeded.  It could be used along with the appstarter. Were you expecting something using Docker Volumes to mount your code? My current Dockerfile does not automatically run “composer install” but I run it from the container using docker exec.

Hi Bosborne,

Thanks for your response!

Your Dockerfile seems to be an excellent base for a production environment. I am particularly interested in how you are handling the built-in Apache and keeping PHP and OS versions up to date.

Yes, I am looking for something using Docker Volumes to mount the code, as it greatly facilitates continuous development and deployment. Running "composer install" manually inside the container with docker exec seems practical and should work well.

Could you share your Dockerfile or a repository where I can see it in action? Additionally, any documentation or example of how you are using it would be very helpful.

Thanks in advance for your help!
Reply
#6

(05-30-2024, 05:41 PM)tarcisiodev1 Wrote:
(05-30-2024, 03:24 AM)Bosborne Wrote: That container uses Ubuntu and is quite old.  I have a Dockerfile that I am getting ready to use in production using the official php image.  It is based on Debian Slim and the variant I use has a builtin Apache web server.  They keep the image up to date with the latest php patches and OS versions.

I use my Dockerfile with several CI4 projects and may need to pare out extra files not néeded.  It could be used along with the appstarter. Were you expecting something using Docker Volumes to mount your code? My current Dockerfile does not automatically run “composer install” but I run it from the container using docker exec.

Hi Bosborne,

Thanks for your response!

Your Dockerfile seems to be an excellent base for a production environment. I am particularly interested in how you are handling the built-in Apache and keeping PHP and OS versions up to date.

Yes, I am looking for something using Docker Volumes to mount the code, as it greatly facilitates continuous development and deployment. Running "composer install" manually inside the container with docker exec seems practical and should work well.

Could you share your Dockerfile or a repository where I can see it in action? Additionally, any documentation or example of how you are using it would be very helpful.

Thanks in advance for your help!
In the Dockerfile, I patch the OS to the latest patches. The official PHP image handles the php & Apache updates, if you use the appropriate tags, For instance, I tag at PHP 8.3 to get all patches but can control moving to 8.4 after it is released. Similarly, I include the Debian version in the tag.

Hopefully I can find time to share this better.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB