Laravel - Laradock 安裝
Laradock 在 Laravel 社群相當知名,它提供了完整套件 Docker-Images及相關設定
讓我們能很簡單的就部署好完整的 Laravel 開發環境
當然也可以支援其他PHP專案,像是 Symfony, CodeIgniter, WordPress 等
這裡介紹如何快速的透過 Laradock 安裝 NGINX, PHP, Composer, MySQL, Redis 及 Beanstalkd
Continue ReadingMarketing, SEO, Web trends, Programming tutorial, Web design, and Life event...
Laradock 在 Laravel 社群相當知名,它提供了完整套件 Docker-Images及相關設定
讓我們能很簡單的就部署好完整的 Laravel 開發環境
當然也可以支援其他PHP專案,像是 Symfony, CodeIgniter, WordPress 等
這裡介紹如何快速的透過 Laradock 安裝 NGINX, PHP, Composer, MySQL, Redis 及 Beanstalkd
Continue ReadingMAC系統會自帶 apache, 在這裡要先將它關閉
暫停apache
sudo apachectl -k stop
關閉開機啟動
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
shift+command+p > Package Control:Install Package > sftp
File>SFTP/FTP/Setup Server
這時會開啟一個json格式的設定檔案
首先,先查看vagant ssh-config
$ vagrant ssh-config
Host homestead-7
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/liaoxiangru/Homestead/.vagrant/machines/homestead-7/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes
設定 Sftp config 檔案,填寫對應資訊
例如:
{
// The tab key will cycle through the settings when first created
// Visit http://wbond.net/sublime_packages/sftp/settings for help
// sftp, ftp or ftps
"type": "sftp",
"sync_down_on_open": true,
"sync_same_age": true,
"host": "127.0.0.1",
"user": "vagrant",
//"password": "password",
"port": "2222",
"remote_path": "/home/vagrant/code",
//"file_permissions": "664",
//"dir_permissions": "775",
//"extra_list_connections": 0,
"connect_timeout": 30,
//"keepalive": 120,
//"ftp_passive_mode": true,
//"ftp_obey_passive_host": false,
"ssh_key_file": "~/.ssh/id_rsa",
//"sftp_flags": ["-F", "/path/to/ssh_config"],
//"preserve_modification_times": false,
//"remote_time_offset_in_hours": 0,
"remote_encoding": "utf-8",
//"remote_locale": "C",
//"allow_config_upload": false,
}
接著存擋為 sftp-config.json
Continue ReadingLaravel 為了讓PHP開發整體體驗都能完善,在local開發的環境設定也提供了相關解決方案
也就是這裡要介紹的 Homestead
Laravel Homestead 是官方所維護的 Vagrant box pre-package
讓你可以直接透過這個環境開發,而不必再獨立安裝PHP、Web server…等軟體
並且不必擔心忘記系統設定,因為 Vagrant boxes 是一次性設定安裝完畢,
如果在安裝流程有發現錯誤,隨時都可以重新安裝環境,並且只需要幾分鐘的時間就能完成
Continue Reading這裡記錄 Services 實作流程
在之前,要先透過 part2 建立了 image gordon/get-started:part2
在這裡,建立 docker-compose.yml ,透過 image 來產生五個重複的 container
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: gordon/get-started:part2
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:80"
networks:
- webnet
networks:
webnet:
接著先執行 swarm 初始化(這部分會在 part 4 介紹)
docker swarm init
接著,執行建立 service app 名稱為 getstartedlab
Continue Reading這裡記錄 Containers 實作流程
在這裡按照下方流程就能快速建立出一個 python demo web
預計將專案放置在 docker_project/get_started/
建立檔案: Dockerfile
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
requirements.txt
Continue ReadingDocker 基本操作常用的指令:
docker build -t friendlyhello . # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyhello # Run "friendlyname" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello # Same thing, but in detached mode
docker container ls # List all running containers
docker container ls -a # List all containers, even those not running
docker container stop <hash> # Gracefully stop the specified container
docker container kill <hash> # Force shutdown of the specified container
docker container rm <hash> # Remove specified container from this machine
docker container rm $(docker container ls -a -q) # Remove all containers
docker image ls -a # List all images on this machine
docker image rm <image id> # Remove specified image from this machine
docker image rm $(docker image ls -a -q) # Remove all images from this machine
docker login # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag # Tag <image> for upload to registry
docker push username/repository:tag # Upload tagged image to registry
docker run username/repository:tag # Run image from a registry
Docker Mount 下圖清楚了說明Docker host的 Volume with bind mounts 以及tmpfs mount 機制
這裡針對 tmpfs 部分進行介紹:
tmpfs mounts 只會儲存於host system的記憶體,不會寫入 host system的 filesystem。
因此,tmpfs mount 資料不會保存在硬碟、Docker host或 container 裡,只會存在container 執行的期間
通常會把 tmpfs mount 應用在非敏感或不必持續保留的狀態資料,舉例來說,swarm service 就是使用 tmpfs mount 去 mount secrets 到 service的 container。
在 Docker 17.06 以上版本,建議使用 –mount flag 來進行 bind mounts, volumes, 或者 tmpfs mount。
tmpfs mounts 最適合使用於不必持續保留的資料,或者當你的應用程式需要寫入大量的非持續保留的資料時。在 host machine 或者 container,適當的採用 tmpfs mount 幾可以讓container執行效能提升。
Continue ReadingDocker Mount 下圖清楚了說明Docker host的 Volume with bind mounts 以及tmpfs mount 機制
這裡針對 Bind Mounts 部分進行介紹:
Bind mounts 在早期 Docker 版本就已經存在,相對於 volumes ,使用 Bind mounts 有一些功能限制:
當 container 在host machine 中的檔案或目錄使用 bind mount
host machine 是以完整的路徑來參照這些檔案或目錄
因此,在Docker host 中不需要存在這些檔案或目錄
若參照的目錄或檔案不存在,則會自動建立。
透過 Bind Mounts 的方式是非常有效率的方式,但使用 bind mounts 需要 host machine 有特定的 filesystem 結構才能運作
如果你正開發一個新的 Docker 應用程式,考慮改用 Volumes 時,就不能直接透過Docker CLI 來管理 bind mounts。
使用 bind mounts 其中一個特點就是,
Continue Reading下圖清楚了說明Docker host的 Volume with bind mounts 以及tmpfs mount 機制
這裡針對 Volumes 部分進行介紹:
Continue ReadingDocker - Storage drivers
為了能有效率的使用 storage drivers,一定要先了解 Docker builds 以及 stores images,container如何使用images。
Storage drivers可以允許你在容器可寫入層(container writable layer) 建立資料
但是,在 Storage driver 操作資料,有這些缺點:
通常會透過 volumes 來保存資料以及改善效能問題
一個 storage driver 負責處理各layer之間的互動
container 與 image 最大的差別就在於頂層可寫入層,在container新增或修改的資料都會存在可寫入層,當container刪除,這個可寫入層就會一併刪除,這底層的 image 則不會影響。
主要是因為每一個 container 都擁有自己的可寫入層,而多個 containers 可以共享同一個 image
例如: 這裡顯示多個 containers 共享同一個 Ubuntu 15.04 image
因此,Storage driver 用來管理 image layers 以及 可寫入層的內容,
雖然所有的 sotrage dirver 處理的方式各有差異,但所有的 driver 使用的都是同樣的 image 堆疊,以及寫入時複製策略(copy-on-write (CoW) strategy)。
可以透過下方指令檢查目前 可寫入層的使用量
docker ps -s
若某一個資料位於底層image,
Continue Reading在 Docker 管理資料
在 container 所建立的檔案,預設都會存放在可容器寫入層(writable container layer)
這表示:
當你建立一個新的 container,會同時在最上層建立一個新的可寫入層(writable layer),也稱為 container layer。
在 container內所有的改變都會在這裡面,例如: 建立新檔案,編輯檔案,刪除檔案,都會寫入這個容器可寫入層。
Continue Readingcomposer require --dev "xethron/migrations-generator"
php artisan --version
Continue Reading
Docker-Compose 是一個可以用來定義且執行多個 Container 應用程式的工具
可以很簡單的透過 Compose 的 yaml 來設定你的container應用程式
並且透過一個指令,就可以建立及啟動所有yaml設定的應用程式
Compose 可以在產品、階段產品、開發或測試項目使用
在使用上大致可以區分為三個過程:
Continue ReadingMySQL 是一個廣泛被使用,開源的關聯式資料庫管理系統( relational database management system, RDBMS)
目前的MySQL執行效能不斷提升,可靠且易於使用,
因此經常被作為網路應用程式開發資料庫的首選.
其中包括 Facebook, Twitter, YouTube, Yahoo 等公司都有使用。
詳細說明可參考官網: www.mysql.com.
這裡將說明如何在 Docker 安裝即執行 MySQL 環境
Continue Reading-d 表示在背景( Detached )執行,Docker 預設前景( foreground )執行
-p 表示將本機 8080 port 的來源轉發到 container 的 80 port
–name 表示為 container 的名稱
–rm 表示當 exit container 時,會移除 container( incompatible with -d )
docker run -d -p 80:80 --name mywebserver nginx
//if need custom port (ex 3000) can do like this
docker run -d -p 3000:80 --name mywebserver nginx
由於 local 還沒有 nginx 的 image,因此Docker 會先執行檢查及下載 nginx image
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
...下載安裝
Status: Downloaded newer image for nginx:latest
安裝完畢之後,就會直接對 nginx image 進行 instance 為 nginx container,並執行
Continue ReadingDocker 在 Mac 環境可以直接透過 Install Docker for Mac 來安裝
前往 Docker for Mac 下載 Docker.dmg 執行安裝
透過下列方式來檢查 docker 版本,確定安裝完畢
docker --version
docker-compose --version
docker-machine --version
Delete all docker containers
docker rm $(docker ps -a -q)
Delete one containers by name
docker rm mycontainername
Delete all docker images
docker rmi $(docker images -q)
Delete images by name
docker rmi images_name
Check Image and containers
//all container (include un-run container)
docker ps -a
//on running container
docker ps
//all images
docker images
Remove Laradock file
rm -rf laradock/
##【 Docker 】
docker-compose down
docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
OPTION:
-d 表示在背景( Detached )執行,Docker 預設前景( foreground )執行
-p 表示將本機 8080 port 的來源轉發到 container 的 80 port
–name 表示為 container 的名稱
–rm 表示當 exit container 時,會移除 container( incompatible with -d )
Continue Reading查詢訂閱狀態與發佈系統的狀態
> PUBSUB xxxchanne
將訊息發送到指定的 channel
> PUBLISH xxxchanne "Message Say Hi"