質問編集履歴

2

実施した手順を追加修正しました

2020/06/11 01:56

投稿

takaoS
takaoS

スコア9

test CHANGED
File without changes
test CHANGED
@@ -730,6 +730,26 @@
730
730
 
731
731
 
732
732
 
733
+ 8. mongodbコンテナにbashで入って、データベースとテーブルを作成
734
+
735
+
736
+
737
+ ```
738
+
739
+ $ docker-compose exec mongo bash
740
+
741
+ # mongo
742
+
743
+ > use sample_db
744
+
745
+ > db.test.insert({phonecompany:'hoge', model:'fuga', price: 10});
746
+
747
+ ```
748
+
749
+
750
+
751
+
752
+
733
753
  ### 参考にしたURL
734
754
 
735
755
 

1

ご質問いただいた内容をもとに、実施した手順と結果を追記しました。

2020/06/11 01:56

投稿

takaoS
takaoS

スコア9

test CHANGED
File without changes
test CHANGED
@@ -66,7 +66,7 @@
66
66
 
67
67
  DB_PORT=27017
68
68
 
69
- DB_DATABASE=terakoya-db
69
+ DB_DATABASE=sample_db
70
70
 
71
71
  DB_USERNAME=root
72
72
 
@@ -122,7 +122,7 @@
122
122
 
123
123
 
124
124
 
125
- 'default' => env('DB_CONNECTION', 'mongodb'),
125
+ 'default' => env('DB_CONNECTION', 'mysql'),
126
126
 
127
127
 
128
128
 
@@ -170,7 +170,7 @@
170
170
 
171
171
  'port' => env('DB_PORT', 27017),
172
172
 
173
- 'database' => env('DB_DATABASE', 'terakoya-db'),
173
+ 'database' => env('DB_DATABASE', 'sample_db'),
174
174
 
175
175
  'username' => '',
176
176
 
@@ -524,6 +524,212 @@
524
524
 
525
525
 
526
526
 
527
+ ### 実施した手順
528
+
529
+
530
+
531
+ 1. Laradockをインストールして、env-exampleから.envを作成
532
+
533
+
534
+
535
+
536
+
537
+ 2. .envを以下のように編集
538
+
539
+
540
+
541
+ ```
542
+
543
+ WORKSPACE_INSTALL_MONGO = true
544
+
545
+ PHP_FPM_INSTALL_MONGO=true
546
+
547
+ ```
548
+
549
+
550
+
551
+
552
+
553
+ 3. コンテナをリビルド
554
+
555
+
556
+
557
+ ```
558
+
559
+ $ docker-compose build workspace php-fpm
560
+
561
+ ...省略...
562
+
563
+ Step 269/269 : WORKDIR /var/www
564
+
565
+ ---> Running in a1385c51232d
566
+
567
+ Removing intermediate container a1385c51232d
568
+
569
+ ---> 1801d0115be1
570
+
571
+ Successfully built 1801d0115be1
572
+
573
+ Successfully tagged laradock_workspace:latest
574
+
575
+ ...省略...
576
+
577
+ Step 152/152 : EXPOSE 9000
578
+
579
+ ---> Running in 17327899c032
580
+
581
+ Removing intermediate container 17327899c032
582
+
583
+ ---> adcb0f84addf
584
+
585
+ [Warning] One or more build-args [INSTALL_CASSANDRA] were not consumed
586
+
587
+ Successfully built adcb0f84addf
588
+
589
+ Successfully tagged laradock_php-fpm:latest
590
+
591
+ ```
592
+
593
+
594
+
595
+
596
+
597
+ 4. コンテナを立ち上げ
598
+
599
+
600
+
601
+ ```
602
+
603
+ $ docker-compose up -d nginx mongo
604
+
605
+ ```
606
+
607
+
608
+
609
+
610
+
611
+ 5. Laravelプロジェクトを作成
612
+
613
+
614
+
615
+ ```
616
+
617
+ $ docker-compose exec workspace bash
618
+
619
+ # composer create-project --prefer-dist laravel/laravel=6.* sampleproject
620
+
621
+ # cd sampleproject/config
622
+
623
+ # vim database.php
624
+
625
+ ```
626
+
627
+
628
+
629
+ ```
630
+
631
+ // 修正した内容
632
+
633
+
634
+
635
+ 'connections' => [
636
+
637
+
638
+
639
+ // ------ 追加 -------
640
+
641
+ 'mongodb' => [
642
+
643
+ 'driver' => 'mongodb',
644
+
645
+ 'host' => env('DB_HOST', 'localhost'),
646
+
647
+ 'port' => env('DB_PORT', 27017),
648
+
649
+ 'database' => env('DB_DATABASE', 'sample_db'),
650
+
651
+ 'username' => env('DB_USERNAME', 'root'),
652
+
653
+ 'password' => env('DB_PASSWORD'),
654
+
655
+ 'options' => [
656
+
657
+ 'database' => '',
658
+
659
+ ]
660
+
661
+ ],
662
+
663
+ // -------------------
664
+
665
+
666
+
667
+ 'sqlite' => [
668
+
669
+ ```
670
+
671
+
672
+
673
+
674
+
675
+ 6. プロジェクトフォルダの.envを編集
676
+
677
+
678
+
679
+ ```
680
+
681
+ # pwd /var/www/sampleproject
682
+
683
+ # vim .env
684
+
685
+ DB_CONNECTION=mongodb
686
+
687
+ DB_HOST=127.0.0.1
688
+
689
+ DB_PORT=27017
690
+
691
+ DB_DATABASE=sample_db
692
+
693
+ DB_USERNAME=root
694
+
695
+ DB_PASSWORD=
696
+
697
+ ```
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+ 7. jenssegers/mongodb をインストール
706
+
707
+
708
+
709
+ ```
710
+
711
+ # pwd /var/www/sampleproject
712
+
713
+ # composer require jenssegers/mongodb
714
+
715
+ Using version ^3.6 for jenssegers/mongodb
716
+
717
+ ./composer.json has been updated
718
+
719
+ ...省略...
720
+
721
+ Package manifest generated successfully.
722
+
723
+ 35 packages you are using are looking for funding.
724
+
725
+ Use the `composer fund` command to find out more!
726
+
727
+ ```
728
+
729
+
730
+
731
+
732
+
527
733
  ### 参考にしたURL
528
734
 
529
735