DEV Community

Cover image for Containerize a simple PHP laravel Application using docker
Philcz
Philcz

Posted on

Containerize a simple PHP laravel Application using docker

Docker is an open-source project for automating the deployment of applications as portable, self-sufficient containers that can run on the cloud or on-premises. Docker is also a company that promotes and evolves this technology, working in collaboration with cloud, Linux, and Windows vendors, including Microsoft.

In this short tutorial we're going to containerize a simple PHP laravel application.

  1. Create the Application image
  2. Go to the folder "cd docker-laravel"
  3. Run Locally "php artisan serve"
  4. Next we write the Dockerfile, this is a set of commands the docker engine uses to build the image. image

FROM php:7.4.15-fpm-alpine3.13

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

WORKDIR /SRC

COPY . /SRC

RUN composer install

EXPOSE 8000

CMD php artisan serve --host=0.0.0.0 --port=8000

"FROM php:7.4.15-fpm-alpine3.13" is the image that your docker image is based on.

Second command downloads and install Composer on the base image

Third Command specifies working directory, where the code will be in the image and container.

Fourth command will copy files from your present working directory to /SRC folder

Fifth command runs the command Composer Install

Sixth command allows access to the app on port 8000

Seventh command starts the server.

  1. Build your image "Docker build -t laraveldocker .
    image

  2. List of images "Docker image ls"
    image

  3. Create a running container from the image "docker run -d -t -p 8080:8000 --name=laraveldocker laraveldocker
    image

  4. List running containers "docker ps"
    image

  5. go to locallhost:8000 to see the running application
    image

Top comments (0)