Laravel docker

 A

“Docker is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere.” https://www.docker.com

In this article, I’ll show you the easiest way to run your Laravel application using Docker. For the brief, first, we’ll create a custom image using Dockerfile. Then later, we’ll create a docker-compose to make things even easier.

Content Overview

  • Dockerfile for Laravel
  • Running the Image with Docker Compose
  • MySQL DB & Artisan Queue Services

#1 Dockerfile for Laravel

Dockerize your Laravel app isn’t very difficult if you’re already familiar with the basic syntax of Docker. I assume you have a Laravel project in your local, if you don’t, you can create one with this command.

FROM php:7.4-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql sockets
RUN curl -sS https://getcomposer.org/installer​ | php -- \
--install-dir=/usr/local/bin --filename=composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
WORKDIR /app
COPY . .
RUN composer install

#2 Running the Image with Docker Compose

Okay, that’s a lot of commands to run an image from the Docker. Fortunately, docker-compose will make things easier. Let’s create a new file named  inside our root project.

version: '3.8'
services:
main:
build:
context: .
dockerfile: Dockerfile
command: 'php artisan serve --host=0.0.0.0'
volumes:
- .:/app
ports:
- 8000:8000

docker-compose.yaml


Comments

Popular posts from this blog

Git commands

How to Debug Android TV App using IP

sales forecasting ML model in retail using the Prophet algorithm from the Facebook Prophet library