---
# System prepended metadata

title: Docker Container Setup
tags: [Docker]

---

---
tags: Docker
---

# Docker Container Setup

```
# clone project
git clone <project-name>

# 專案建立初期都要先 build
docker-compose up --build

# docker setup (-d: detach, running containers in the background)
docker-compose up -d

=> 這邊如果沒有到 docker -> resources -> file sharing 設定 redis path 的話，可能會報錯

redis path: /data/redis-data

# enter into docker container bash
docker-compose exec <project-name> bash


# install packages
cd <project-name>
composer install
npm install


# set hosts
<!-- 這是在本機端 -->
vi /etc/hosts
---
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1      localhost
# add next line - 這邊如果網域名稱不同的話也要新增新的網域名稱，否則會找不到(例如： devapi.ecfit.com 就會找不到 API 的網域)
127.0.0.1      dev.ecfit.com
255.255.255.255 broadcasthost
::1            localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
~
---


# set 000-default.config
vi 000-default.config
---
<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
    ServerName phpmyadmin.com
    ServerAlias dev.phpmyadmin.com
    DocumentRoot /var/www/html/phpMyAdmin
</VirtualHost>
<VirtualHost *:80>
# add next line
    ServerName dev.ecfit.com
    DocumentRoot /var/www/html/howsoul/public
</VirtualHost>
ServerSignature Off
ServerTokens Prod
---


# set .gitignore in <project-name>
# also ignore .gitignore itself
.gitignore
/node_modules
/public/hot
/public/storage
/public/js
/public/css
/public/mix-manifest.json
/public/sitemap.xml
/storage/*.key
/storage
/vendor
.env
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
package-lock.json
cypress.json


# set .gitignore in project root
# also ignore .gitignore itself
.gitignore
/mysql



# set storage file and 777
cd storage
mkdir framework
cd framework
mkdir cache
mkdir views
mkdir sessions
cd <project-name>
chmod -R 777 storage


# set .env
# env sample
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:UyHewLzt7UnfGzbuYHNO2JjgI8HYaLSTXMsr+6yZSjs=
APP_DEBUG=true
APP_URL=http://dev.ecfit.com
LOG_CHANNEL=stack
DB_CONNECTION=mysql

DB_HOST=ecfit_howsoul_docker_mysql_1
# 測試機 host
# DB_HOST=34.80.12.165
DB_PORT=3306
DB_DATABASE=howsoul
DB_USERNAME=root
DB_PASSWORD=1234
# 測試機密碼
# DB_PASSWORD=howsoulcrossecfit

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=silber-huang@ecfit.com.tw
MAIL_PASSWORD=silber8717622ifit
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY=“${PUSHER_APP_KEY}”
MIX_PUSHER_APP_CLUSTER=“${PUSHER_APP_CLUSTER}”
JWT_SECRET=HnXHS4YkDrZLfR9Yo0qjMy9tupoSvOrLogw4VhMTFIGlOGgoHIDuyVAecbJsIcfq
MIX_FB_CLIENT_ID=423720159066199
MIX_API_ROUTE=http://dev.ecfit.com/api/
FB_CLIENT_ID=423720159066199
FB_CLIENT_SECRET=4c6341059d88f1fe10cf00a6b41c5b62
FB_REDIRECT=https://howsoul.belight.cc/facebook-reg-callback
GOOGLE_CLIENT_ID=498402186559-438evqj1vn6om66pn933g3aifrmroupv.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=FKKkR5h4Z8sX5ALDJgPDe_gb
GOOGLE_REDIRECT=https://howsoul.belight.cc/google-reg-callback
WEIXIN_MINI_PROGRAM_CLIENT_ID=wxae2a5afff6560737
WEIXIN_MINI_PROGRAM_CLIENT_SCERET=6a2e40f1c71d8230f92ce982c7be3374
SHELL_POINT_RATE=5000
```

Windows 一些額外須注意的事情(win10 限定，win10以下你還是換 mac 吧)
* Windows 在 docker 相關指令都需加 winpty 前輟
* clone 下專案時先把 docker/run.sh 改為 UNIX 編碼
* 如果碰到 npm run watch 、 npm run build 等等失敗，並噴關於 node-sass 的錯誤時，把 node_modules 整個刪除再跑一次 npm install 應該可以修復(linux 也可能碰到)
* windows 須至 C:\Windows\System32\drivers\etc 裡面的 hosts 檔案設定 host，不必做 vi /etc/hosts
* 如果碰到 cross env 的問題，基本上也是把 node_modules 刪掉重裝應該可以修正
* Windows 我是都使用 Git Bash 取代內建的 cmd，Cmder 也可但之前踩過路徑的雷