- Hands-On Full Stack Web Development with Angular 6 and Laravel 5
- Fernando Monteiro
- 244字
- 2021-07-23 19:18:47
Setting up the database inside a Docker container
It's now time to configure our database. If you use Homestead, you probably have your database connection configured and working well. To check, open your Terminal and type the following command:
php artisan tinker DB::connection()->getPdo();
If everything goes well, you will see the following message:

For this example, however, we are using Docker, and we need to do some configuration to accomplish this task:
- Inside of the root project, open the .env file and look at line 8 (the database connection), which looks as follows:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Now, replace the preceding code with the following lines:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel-angular-book
DB_USERNAME=laravel-angular-book
DB_PASSWORD=123456
Note that we need to change a bit to get the Docker MySQL container directions; if you don't remember what you chose in the PHPDocker.io generator, you can copy it from the container configuration.
- Open docker-compose.yml at the root directory.
- Copy the environment variables from the MySQL container setup:
mysql:
image: mysql:8.0
entrypoint: ['/entrypoint.sh', '--character-set-server=utf8', '--
collation-server=utf8_general_ci']
container_name: larahell-mysql
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=larahell
- MYSQL_DATABASE=larahell-angular-book
- MYSQL_USER=larahell-user
- MYSQL_PASSWORD=123456
ports:
- "8083:3306"
Now, it's time to test our connection.
- In your Terminal window, type the following command:
docker-compose exec php-fpm bash
- Finally, let's check our connection; type the following command:
php artisan tinker
DB::connection()->getPdo();
You should see the same message as the previous screenshot. Then, you will have everything you need to go ahead with the example.
- 物聯(lián)網(wǎng)(IoT)基礎(chǔ):網(wǎng)絡(luò)技術(shù)+協(xié)議+用例
- 萬物互聯(lián):蜂窩物聯(lián)網(wǎng)組網(wǎng)技術(shù)詳解
- TCP/IP入門經(jīng)典(第5版)
- PLC、現(xiàn)場總線及工業(yè)網(wǎng)絡(luò)實(shí)用技術(shù)速成
- 面向物聯(lián)網(wǎng)的嵌入式系統(tǒng)開發(fā):基于CC2530和STM32微處理器
- 大話社交網(wǎng)絡(luò)
- Learning Swift(Second Edition)
- Microsoft Dynamics CRM 2011 Applications(MB2-868) Certification Guide
- 光纖通信系統(tǒng)與網(wǎng)絡(luò)(修訂版)
- jQuery Mobile Web Development Essentials
- 園區(qū)網(wǎng)絡(luò)架構(gòu)與技術(shù)
- Getting Started with tmux
- 物聯(lián)網(wǎng)
- Corona SDK Application Design
- 一本書讀懂移動物聯(lián)網(wǎng)