Open yaodehaung opened 4 years ago
$ docker build .
or
$ docker build -t="your-name/image-name" .
docker push your-name/image-name
Docker Compose 的前身是 fig,它是一個用於管理部署 Docker 容器的 Python 專案,後來變成 Docker Composer,此工具必須要額外安裝(在 Docker for Windows 和 Docker for Mac 中已內建)。docker stack 則是包含在 Docker 引擎中的功能,內部是用 Go 編寫,必須配合 swarm 模式才能使用。 Docker Compose 和 docker stack 都使用 docker-compose.yml,但 docker stack 只支援版本 3,兩者支援的指令有些許不同。 docker stack 無法 build 映像檔,須使用已經存在的映像檔。 Docker Compose 更適合用在開發環境。
$docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
tl91oppp2c6u my_app_db replicated 1/1 postgres:latest *:5432->5432/tcp
p37jjflvy7cj my_app_visualizer replicated 1/1 dockersamples/visualizer:stable *:8080->8080/tcp
x57ie7l4qq1w my_app_web replicated 10/10 twtrubiks/my_django:latest *:8000->8000/tcp
$ docker service inspect my_app_web // 加--pretty 可以顯示比較漂亮
[
{
"ID": "x57ie7l4qq1wi7nfgxoddk2yb",
"Version": {
"Index": 9145
},
"CreatedAt": "2020-10-08T06:53:38.809859639Z",
"UpdatedAt": "2020-10-08T07:00:42.955704349Z",
"Spec": {
"Name": "my_app_web",
"Labels": {
"com.docker.stack.image": "twtrubiks/my_django",
"com.docker.stack.namespace": "my_app"
},
"TaskTemplate": {
"ContainerSpec": {
"Image": "twtrubiks/my_django:latest@sha256:1a8367dc8bf3f49504fa4e3162ab811e65f7c15077f45665b221497784928fe3",
"Labels": {
"com.docker.stack.namespace": "my_app"
},
"Privileges": {
"CredentialSpec": null,
"SELinuxContext": null
},
"StopGracePeriod": 10000000000,
"DNSConfig": {},
"Isolation": "default"
},
"Resources": {},
"RestartPolicy": {
"Condition": "on-failure",
"Delay": 5000000000,
"MaxAttempts": 0
},
"Placement": {
"Platforms": [
{
"Architecture": "amd64",
"OS": "linux"
}
]
},
"Networks": [
{
"Target": "rahc4nqk4pjnowfy4qqn8k7yb",
"Aliases": [
"web"
]
}
],
"ForceUpdate": 0,
"Runtime": "container"
},
"Mode": {
"Replicated": {
"Replicas": 10
}
},
"UpdateConfig": {
"Parallelism": 2,
"FailureAction": "pause",
"Monitor": 5000000000,
"MaxFailureRatio": 0,
"Order": "stop-first"
},
"RollbackConfig": {
"Parallelism": 1,
"FailureAction": "pause",
"Monitor": 5000000000,
"MaxFailureRatio": 0,
"Order": "stop-first"
},
"EndpointSpec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 8000,
"PublishedPort": 8000,
"PublishMode": "ingress"
}
]
}
},
"PreviousSpec": {
"Name": "my_app_web",
"Labels": {
"com.docker.stack.image": "twtrubiks/my_django",
"com.docker.stack.namespace": "my_app"
},
"TaskTemplate": {
"ContainerSpec": {
"Image": "twtrubiks/my_django:latest@sha256:1a8367dc8bf3f49504fa4e3162ab811e65f7c15077f45665b221497784928fe3",
"Labels": {
"com.docker.stack.namespace": "my_app"
},
"Privileges": {
"CredentialSpec": null,
"SELinuxContext": null
},
"Isolation": "default"
},
"Resources": {},
"RestartPolicy": {
"Condition": "on-failure",
"MaxAttempts": 0
},
"Placement": {
"Platforms": [
{
"Architecture": "amd64",
"OS": "linux"
}
]
},
"Networks": [
{
"Target": "rahc4nqk4pjnowfy4qqn8k7yb",
"Aliases": [
"web"
]
}
],
"ForceUpdate": 0,
"Runtime": "container"
},
"Mode": {
"Replicated": {
"Replicas": 0
}
},
"UpdateConfig": {
"Parallelism": 2,
"FailureAction": "pause",
"MaxFailureRatio": 0,
"Order": "stop-first"
},
"EndpointSpec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 8000,
"PublishedPort": 8000,
"PublishMode": "ingress"
}
]
}
},
"Endpoint": {
"Spec": {
"Mode": "vip",
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 8000,
"PublishedPort": 8000,
"PublishMode": "ingress"
}
]
},
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 8000,
"PublishedPort": 8000,
"PublishMode": "ingress"
}
],
"VirtualIPs": [
{
"NetworkID": "lhvinv6gcs2652vzi13wvdj37",
"Addr": "10.0.0.29/24"
},
{
"NetworkID": "rahc4nqk4pjnowfy4qqn8k7yb",
"Addr": "10.0.8.17/24"
}
]
}
}
]
$ docker network disconnect
docker@vm1:~/dockerLab$ docker service ps my_app_web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
rgwcficzpfgj my_app_web.1 sef1548/dockerlab:1.0 vm2 Ready Rejected less than a second ago "No such image: sef1548/docker…"
a6p13fjy6z2i \_ my_app_web.1 sef1548/dockerlab:1.0 vm1 Shutdown Rejected 5 seconds ago "No such image: sef1548/docker…"
ito80il25n10 \_ my_app_web.1 sef1548/dockerlab:1.0 vm2 Shutdown Rejected 10 seconds ago "No such image: sef1548/docker…"
nmecnarlk16b \_ my_app_web.1 sef1548/dockerlab:1.0 vm1 Shutdown Rejected 15 seconds ago "No such image: sef1548/docker…"
vf48elqw931a \_ my_app_web.1 sef1548/dockerlab:1.0 vm2 Shutdown Rejected 20 seconds ago "No such image: sef1548/docker…"
docker-machine
Docker Compose
or
Docker Compose 的前身是 fig,它是一個用於管理部署 Docker 容器的 Python 專案,後來變成 Docker Composer,此工具必須要額外安裝(在 Docker for Windows 和 Docker for Mac 中已內建)。docker stack 則是包含在 Docker 引擎中的功能,內部是用 Go 編寫,必須配合 swarm 模式才能使用。 Docker Compose 和 docker stack 都使用 docker-compose.yml,但 docker stack 只支援版本 3,兩者支援的指令有些許不同。 docker stack 無法 build 映像檔,須使用已經存在的映像檔。 Docker Compose 更適合用在開發環境。
REF
初探Docker Machine Docker(五):Docker 三剑客之 Docker Machine Docker 學習筆記 docker-compose.yml How to Manage Docker Machine With Swarm on Virtualbox docker-swarm-tutorial HAproxy docker swarm 部署記錄
Docker Swarm + HAProxy 实现高可用