yum install epel-release –y
yum clean all
yum list
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
確認移除
docker info
安裝必要的 repository
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
使用 stable repository
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
啟用 edge (可自行決定是否啟用)
sudo yum-config-manager --enable docker-ce-edge
(若不想啟用 edge,也可以直接關閉):
sudo yum-config-manager --disable docker-ce-edge
安裝新版本
sudo yum install docker-ce
docker info
sudo systemctl start docker #運行Docker守護進程
sudo systemctl stop docker #停止Docker守護進程
sudo systemctl restart docker #重啟Docker守護進程
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
添加權限
Continue ReadingLaradock 在目前釋出的最新版本,會直接引用 MySQL latest version (MySQL 8.x)
由於 MySQL 8.x 版本的新密碼格式會引發 mysql container 一些錯誤,
The server requested authentication method unknown to the client...
因此,必須在安裝 laradock 調整 MySQL 版本
(若已經安裝且執行過 docker-compose up..,同樣可適用)
Continue ReadingLaradock 在 Laravel 社群相當知名,它提供了完整套件 Docker-Images及相關設定
讓我們能很簡單的就部署好完整的 Laravel 開發環境
當然也可以支援其他PHP專案,像是 Symfony, CodeIgniter, WordPress 等
這裡介紹如何快速的透過 Laradock 安裝 NGINX, PHP, Composer, MySQL, Redis 及 Beanstalkd
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 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