Running Laravel Artisan Command on Docker

                                      Most developers know what is a Docker. It is a tool which can be used to make it easier to create, deploy and run applications using containers. Containers are used to pack up an application with all its parts like libraries and other dependencies and ship it as a package. When using Docker based local dev environment you need to know how to run Laravel Artisan commands efficiently. There are many things to consider while using Artisan commands with Docker. You need to create a new container with ssh for running commands is one such thing. The best practices considering the usage of  Docker is running each processes inside its own container. Then create an image to make  new containers for running artisan commands. You can create docker images as given below.

FROM base_image_with_LAMP_stack_and_dependencies


WORKDIR /var/www/html/app


COPY composer.json composer.json


RUN composer install --no-scripts --no-dev --no-autoloader


COPY . .


RUN echo 'chown -R www-data:www-data /var/www/ \

&& composer dump-autoload \

&& cp .env.example .env \

&& php artisan key:generate \

&& php artisan migrate \

&& apachectl -D FOREGROUND' >>/root/ && \

 chmod 755/root/



CMD /root/