Testing Docker setup for Laravel Development
Install project in development
- Clone this repo and name it oppi
git clone <this repo url> testing-docker
- Download, install and launch Docker Community Edition
- cd into the project directory
testing-docker
- Here you have two choices, if you have composer installed or not:
- If you have composer installed, run
composer install
- If you don't have composer installed you can run it through docker, it will take some time but you at least wont have to install composer. Run
docker run --rm -v $(pwd):/app composer/composer install
. A tip for the future is to make an alias foralias composerDocker="docker run --rm -v $(pwd):/app composer/composer"
that way you can write onlycomposerDocker install
etc to use composer this way. - Build and run the docker, this will take a couple of minutes depending on bandwidth and computer speed:
docker-compose up
this command will, after installation, be showing a live console from the development server. - Migrate and seed the database but first you have to read more about how it works.. When you know how to run commands on the server: run
php artisan migrate --seed
- Access the page by visiting 0.0.0.0 in your browser.
Login
Email: admin@admin.com Pw: 1234 Email: user@user.com Pw: 1234
Running commands on the server
For example php artisan migrate
To run commands on the server you have to access the server environment.
You can access the server and run commands directly to it by
docker-compose exec app <your-commands-here>
That means that we can run
docker-compose exec app php artisan migrate
If we want to, we can also "login" to the server and use it through the command line freely:
docker-compose exec app bash
Now you may run any command as if you where on the actual server.
Tip!
Add an aliases to make life easier, for example:
alias phpd="docker-compose exec app php"
So, when you run phpd artisan migrate
you run it on the server
Access the database locally
You may access the database through third party program like Sequel Pro.
Host (värd): 0.0.0.0
Username: oppi
Password: secret
Database: oppi-docker
Port: 33061