This is a small project I started to effciently start Laravel projects with reduced dev ops delays.
The container includes the following packages installed on Alpine:
- Core utilities: curl, unzip
- PHP 7.x from apk services
- PHP extensions required for the Laravel project
This is where volumes are used to interact with the container project file. Run the following command to link your project folder.
Run the docker command to pull the image from the Docker repo.
docker pull johnnyhuy/laravel
Start a container from the image you have downloaded.
docker run -p 80:80 -v $PWD:/var/www/laravel -d johnnyhuy/laravel
Note: $PWD is the current directory.
We'll be using docker compose to create a config file to include the MySQL image and link it to the johnnyhuy/laravel image. Create a docker-compose.yml in your project folder as shown.
version: "3"
services:
web:
build: ./
image: johnnyhuy/laravel:latest
ports:
- "80:80"
volumes:
- .:/var/www/laravel
links:
- "db:database"
db:
image: mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: "YOUR ROOT PASSWORD HERE"
MYSQL_DATABASE: "YOU MYSQL DATABASE NAME HERE (OPTIONAL)"
Create a docker-compose.yml in your project folder as shown. Be sure to replace MySQL root password and database.
version: "3"
services:
web:
build: ./
image: johnnyhuy/laravel:latest
ports:
- "80:80"
- "443:443"
links:
- "db:database"
db:
image: mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: "YOUR ROOT PASSWORD HERE"
MYSQL_DATABASE: "YOU MYSQL DATABASE NAME HERE (OPTIONAL)"
Note: this is similar to the development method but without the volumes.
Download the Dockerfile from this git or docker repository.
Build the docker image by running the following command.
docker-compose build
Run the container.
docker-compose up -d