Laravel homestead-docker
Install laravel in a container with homestead
Laravel homestead-docker
Create a homestead docker container for your development env. (Adapted from laravel homestead provisionning script)
Install docker && docker compose
please refer to these tutorials:
- install docker (https://docs.docker.com/installation/ubuntulinux/)
1
curl -sSL https://get.docker.com/ | sh - install docker compose (https://docs.docker.com/compose/install/)
1 2
sudo curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
Pull homestead image
1
docker pull shincoder/homestead:php7.3
Clone && Edit docker-compose.yml
1
git clone https://github.com/shincoder/homestead-docker.git
rename docker-compose.dist.yml to docker-compose.yml then edit the file with you own
paths and ports.
Start your containers
There are only two containers to run. web container ( includes everything except your database ), and mariadb container.
1
sudo docker-compose up -d
Increase PHP memory limit
Increase the limit in your php.ini file /etc/php/7.3/cli/php.ini:
1
2
; Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
SSH into the container (password: secret):
1
ssh -p 2222 homestead@localhost
Add a virtual host
Assuming you mapped your apps folder to /apps (you can change mappings in the docker-compose.yml file,
it’s prefered to use absolute paths), you can do:
1
2
3
cd /
sudo ./serve.sh myapp.dev /apps/myapp/public
sudo supervisorctl restart all
In the host, update /etc/hosts to include your app domain:
1
127.0.0.1 myapp.dev
Upgrade composer to version 2 (optional)
1
sudo composer self-update --stable
That’s it
Our web container starts nginx, php-fpm, redis, beanstalk. and has npm, gulp, bower…etc
Notes
- Since the web and database containers are linked you can use
mysqlas the host in your.envfile with an empty password to properly connect to your database.1 2 3 4
DB_HOST=mysql DB_PORT=3306 DB_USERNAME=root DB_PASSWORD=