Setup laravel project with docker
Here we will learn about how to create laravel project using docker on window system. You have to first install the docker desktop application and install the wsl (window subsystem linux) on your window machine.
Install wsl if you are using windows operating system
https://learn.microsoft.com/en-us/windows/wsl/install
To install wsl on windows system open terminal and run below command
wsl --install
Run wsl --list --online
command to get the list of all available distro.
Now run wsl --install -d Ubuntu-22.04
to install the ubuntu-22.04 version.
Now set the version using command wsl --set-version Ubuntu-22.04 2
.
To enable wsl on system you have to click on the Start menu and type "Windows features
" into the search bar and click on the option "Turn Windows Features On or Off
". Now Tick the "Windows Subsystem for Linux
" checkbox and press the OK button.
Now you have to restart the system.
Download docker installer
https://www.docker.com/products/docker-desktop/
Run docker desktop installer.exe to install the docker desktop app on your system (after installation you have to create account and login to docker to run docker desktop application)
Checked Checkbox Use the WSL 2 based engine
avaible in General section under settings option in docker desktop application.
In docker desktop you have to reach the setting > Resources > wsl integration and make changes as per below
Click on checkbox Enable integration with my default WSL distro
and switch on the option ubuntu
available in list.
Restart the docker
Start a new terminal session of ubuntu terminal
Now run below command to create the project
curl -s https://laravel.build/example-app | bash
Move to project directory cd example-app command and run below command
./vendor/bin/sail up
Run database migration using below command
./vendor/bin/sail artisan migrate
Create a file named Dockerfile
and paste below code in it and save the file.
FROM php:7.4-apache
# Install dependencies
RUN apt-get update && apt-get install -y \
git \
unzip \
libzip-dev \
&& docker-php-ext-install zip pdo pdo_mysql \
&& a2enmod rewrite
# Copy application files
COPY . /var/www/html
# Set permissions
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
# Expose port
EXPOSE 80
Change ports under laravel.test: to 8000:80 in docker-compose.yml file
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.3
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.3/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- "8000:80"
Start the container using below command from project root directory
docker-compose up -d
To stop the docker you can use below command
docker-compose down
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Laravel get single row by id
- Redirect from www to non www in laravel using htaccess
- First and last item of the array using foreach iteration in laravel blade
- Laravel save object to database
- Docker important commands to run laravel application with docker
- How to upload local Laravel project to server ?
- Update record after find method in lavavel
- Call to a member function pluck() on array
- Laravel URL validation not working
- How to check column value of a record is null or not in laravel
- Display data in table using foreach in Laravel
- Insert data with form validation using ajax in laravel
- How to get file extension from input type file in laravel
- How to display a specific word from a string in laravel
- Wheredate in laravel not working
- Undefined property: stdClass::$title
- How to get date from created_at field in laravel
- Display first n record from collection in laravel view
- How to pass query string to url in laravel
- How to check records exist in loaded relationship in Laravel blade view
- How to generate .env file for laravel?
- How to get only time from created_at in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- How to get specific columns using Laravel eloquent methods
- How to add active class to menu item in laravel