php-laravelHow do I create a Docker image for a Laravel application using PHP?
Creating a Docker image for a Laravel application using PHP is easy.
- First, create a
Dockerfilewith the following content:
FROM php:7.2-apache
# Install dependencies
RUN apt-get update && apt-get install -y \
libzip-dev \
zip \
unzip
# Enable Apache mod_rewrite
RUN a2enmod rewrite
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql zip
# Copy our application code
COPY . /var/www/html/
# Set the working directory
WORKDIR /var/www/html
# Expose port 80
EXPOSE 80
- Then, build the image using the
docker buildcommand:
docker build -t laravel-app .
- Finally, run the container:
docker run -d -p 80:80 laravel-app
The image should be now created and the Laravel application should be running.
Parts of the code explained:
FROM php:7.2-apache: This line specifies the base image to use for the Docker image.RUN apt-get update && apt-get install -y: This command installs the necessary packages for the application.RUN a2enmod rewrite: This command enables the Apache mod_rewrite module.RUN docker-php-ext-install pdo_mysql zip: This command installs the PHP extensions needed for the application.COPY . /var/www/html/: This command copies the application code into the container.WORKDIR /var/www/html: This command sets the working directory for the container.EXPOSE 80: This command exposes port 80 to the host machine.
Helpful links
More of Php Laravel
- How do I set up a .gitlab-ci.yml file for a Laravel project using PHP?
- How can I use Laravel Sail to develop a web application with PHP?
- How do I configure Xdebug in the php.ini file for a Laravel project?
- How can I use the Laravel WhereIn method in PHP?
- How do I use PHP Laravel Tinker to debug my code?
- How do I set up notifications in a Laravel application using PHP?
- ¿Cómo configurar PHP y Laravel desde cero?
- How can I set up a Telegram bot using PHP and Laravel?
- How can I configure Nginx to work with Laravel on a PHP server?
- How do I install Laravel using XAMPP and PHP?
See more codes...