{"id":722,"date":"2024-11-28T11:33:07","date_gmt":"2024-11-28T16:33:07","guid":{"rendered":"https:\/\/waterloobae.com\/?p=722"},"modified":"2025-08-20T14:23:34","modified_gmt":"2025-08-20T18:23:34","slug":"laravel-how-to-build-laravel-application-with-docker-2-2","status":"publish","type":"post","link":"https:\/\/waterloobae.com\/blog\/2024\/11\/28\/laravel-how-to-build-laravel-application-with-docker-2-2\/","title":{"rendered":"[Laravel] How to build Laravel application with Docker 2\/2"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\" id=\"what-is-this\">What is this?<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">When more than one developer or machine are needed for development, repository like Git makes the task easier. This article explains how to add new machine or a new developer to your development team while using Laravel Sail\/Docker.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-clone-this-repository-to-your-local-machine\">1. Clone the repository to your local machine<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can clone the repository with the command below. URL can be obtained from the repository.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">git clone URL<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-create-env-file\">2. Create .env file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Copy .env file from .env.example or get it from your original project.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">cp .env.example .env <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-install-composer-packages\">3. Install Composer packages.<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"permission--ownership\">Permission &amp; Ownership<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Permission of 777 is not recommended. However, it is easier to change to 777 and change back to 775 if error occurs for storage or bootscrap\/cache directories.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo chown -R $(id -u):$(id -g) storage bootstrap\/cache &amp;&amp; \\\nsudo chmod -R 777 storage  bootstrap\/cache\n\nsudo chown -R $(id -u):$(id -g) storage  bootstrap\/cache &amp;&amp; \\\nsudo chmod -R 775 storage  bootstrap\/cache\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Install Composer packages by running Docker command below to keep the version correct. Or you can run composer install from your local machine if it does not work it is recommended to install with local composer first<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">composer install<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">OR &#8220;composer update&#8221; might be needed. You may install the application&#8217;s dependencies by navigating to the application&#8217;s directory and executing the following command. This command uses a small Docker container containing PHP and Composer to install the application&#8217;s dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">mkdir -p vendor &amp;&amp; docker run --rm \\\n    -u \"$(id -u):$(id -g)\" \\\n    -v \"$(pwd):\/var\/www\/html\" \\\n    -w \/var\/www\/html \\\n    laravelsail\/php83-composer:latest \\\n    composer install --ignore-platform-reqs\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/laravel.com\/docs\/11.x\/sail#installing-composer-dependencies-for-existing-projects\">https:\/\/laravel.com\/docs\/11.x\/sail#installing-composer-dependencies-for-existing-projects<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Linux, xml writer might be needed. It can be installed as<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo apt-get install php-xml<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7-install-npm-packages-and-run-dev\">4 Install npm packages and run dev.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">npm packages should be installed and npm run dev is necessary to compile assets.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$npm install\n$npm run dev<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">OR<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$sail npm install\n$sail npm run dev<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-sail-build-with\">5. Sail build with<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sail build is not required, however, it can be excuted when errors occur.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sail down\nsail build --no-cache\nsail up -d<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5-generate-application-key\">6 Generate Application key<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Laravel application key is needed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sail artisan key:generate<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6-migarate-database\">7 Migarate Database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Database can be created with migration<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sail artisan migrate<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"debugging\">Debugging &amp; Useful commands<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In case you encounter some errors. Some commands below might help to debug.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sail artisan config:clear\nsail artisan cache:clear<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"set-permissions\">Set permissions<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">find . -type d -exec chmod 775 {} \\;\nfind . -type f -exec chmod 664 {} \\;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"access-docker-shell\">Access docker shell<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sail exec laravel.test bash<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"deploying-on-local-machine-without-sail\">Deploying on local machine Without Sail<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">php artisan serve\nphp artisan serve --host=0.0.0.0 --port=8080<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What is this? When more than one developer or machine are needed for development, repository like Git makes the task easier. This article explains how to add new machine or a new developer to your development team while using Laravel Sail\/Docker. 1. Clone the repository to your local machine You can clone the repository with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,4],"tags":[],"class_list":["post-722","post","type-post","status-publish","format-standard","hentry","category-crowdmark","category-it-tips"],"_links":{"self":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts\/722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/comments?post=722"}],"version-history":[{"count":9,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts\/722\/revisions"}],"predecessor-version":[{"id":801,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts\/722\/revisions\/801"}],"wp:attachment":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/media?parent=722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/categories?post=722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/tags?post=722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}