curl https://get.docker.com | bash
# 起一個在背景使用shell的服務
bash-3.2$ docker run -i -t -d nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
be8881be8156: Already exists
65206e5c5e2d: Pull complete
8e029c3e2376: Pull complete
Digest: sha256:291e15f504cdc40aeedcd29b59f0079c794e18f22cd8a6a6d66d646b36f1d51b
Status: Downloaded newer image for nginx:latest
73ac5cf4f67f64ed5eb4e4c6e97bad6b037cdd3097b24799dacc536b6f621c9a
# 這樣就可以進去nginx了
bash-3.2$ docker exec -ti 73 bash
root@73ac5cf4f67f:/#
docker run -i -t -d -p 80:80 nginx
docker run -i -t -d -p 80:80 --restart always nginx
docker run -i -d -t -p 80:80 --link node nginx
FROM nginx:alpine
ARG DOMAIN
ENV DOMAIN=$DOMAIN
COPY default.conf /etc/nginx/conf.d/default.conf
ENTRYPOINT ["nginx", "-g", "daemon off;"]
docker build . -t image:tag --build-arg DOMAIN=example.com
# 如果FOO有資料的話就是叫做FOO,如果沒的話就是叫做bar
${FOO:+bar}
# 如果FOO沒資料的話就是empty(空值),如果有的話就是bar
${FOO:-bar}
Text
# 先把需要上傳的container包裝成 domain/project(group)/name 的image
docker commit container registry.gitlab.com/sample/code:latest
# 登入registry
docker login -u user -p password registry.gitlab.com
# 將image上傳到registry
docker push registry.gitlab.com/sample/code:latest
# 使用上傳的image建立container
docker run -i -d -t registry.gitlab.com/sample/code:latest
version: "3"
services:
php:
build:
context: .
dockerfile: Dockerfile-php
restart: always
env_file:
- ./.env
volumes:
- ./php:/src
db:
container_name: tickets-db
image: mariadb:10
restart: always
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_USER=${DB_USERNAME}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_RANDOM_ROOT_PASSWORD=true
web:
image: nginx:1.15.2-alpine
restart: always
ports:
- 80:80
- 443:443
depends_on:
- php
- db
- redis
volumes:
- ./php:/src
- ./web:/etc/nginx/conf.d
redis:
image: redis:4.0.11-alpine
restart: always
沒辦法安裝的請用這個
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_DEFAULT_REGION=
export KOPS_STATE_STORE=
export NAME=cluster.k8s.local
# 如果已經有的可以省略
aws s3api create-bucket --bucket $KOPS_STATE_STORE \
--create-bucket-configuration LocationConstraint=ap-northeast-1
kops create cluster --master-size t2.small \
--node-size t2.small --zones ap-northeast-1a $NAME
# 等待大約兩分鐘
kubectl get nodes
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-world-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.org/ssl-services: "hello-world-svc"
spec:
tls:
- hosts:
- api.sample.com
secretName: tls-certificate
rules:
- host: api.sample.com
http:
paths:
- path: /
backend:
serviceName: hello-world-svc
servicePort: 8080
docker | kubernetes |
---|---|
docker run | kubectl run/kubectl create deployment |
docker ps | kubectl get pods |
docker attach | kubectl attach |
docker exec | kubectl exec |
docker logs | kubectl top pod |
以及擴容方案
簡報
HWD TG
CapsLock, Studio
Event TG