使用Docker、CoreOS、Mesos部署可扩展的Web应用

2016-06-30  本文已影响101人  咖灰

为我的Web应用程序创建Docker镜像


这里是我用来构建Docker镜像的Dockerfile:

FROM golang

WORKDIR /

RUN git clone https://djannot:xxxx@github.com/djannot/s3pics.gitWORKDIR/s3pics

RUN go build

EXPOSE 8080

构建镜像时我使用了--no-cache参数,以确保最新的源代码是从GitHub上克隆的。

core@coreos1 /media/share1/Dockerfiles/s3pics $ docker build--no-cache.

Sending build context to Docker daemon 2.048kB 

Sending build context to Docker daemon 

Step0:FROM golang

--->1ea210e0e1f6

Step1:WORKDIR /

--->Running  in  f6987b175723

--->022aa96f56d0

Removing intermediate container f6987b175723

Step2:RUN git clone https://djannot:xxxx@github.com/djannot/s3pics.git

--->Running in 54d6a32e90ba

Cloninginto's3pics'...

--->3369bca87577

Removing intermediate container 54d6a32e90ba

Step3:WORKDIR /s3pics

--->Running in d875bc08eac9

--->73946142ea54

Removing intermediate container d875bc08eac9

Step4:RUN go build

--->Running in e0bd59c1f28b

--->baebdd1b633e 

Removing intermediate container e0bd59c1f28b

Step5:EXPOSE 8080

--->Running in 16d3fa9be1c5

--->815b7aed2c83

Removing intermediate container 16d3fa9be1c5

Successfully built 815b7aed2c83

最后,我推送镜像到Docker registry。

core@coreos1/media/share1/Dockerfiles/s3pics $ docker push 10.64.231.45:5000/s3pics:2.0

The push refers to a repository [10.64.231.45:5000/s3pics] (len:1)

Sending image list

Pushing repository 10.64.231.45:5000/s3pics (1tags) 

Image 511136ea3c5aal ready pushed,skipping

Image 16386e29a1f4already pushed,skipping

Image 835c4d274060 already pushed,skipping

Image 22c23ce0a90c already pushed,skipping

Image 3f1e6432f26e already pushed,skipping

Image 7982826b1e59 already pushed,skipping

Image 1dafbd563f5a already pushed,skipping

Image 7a94d87545e8 already pushed,skipping

Image e2d60f7b3d07 already pushed,skipping

Image 4f23222e2f74 already pushed,skipping

Image 258b590ccdee already pushed,skipping

Image 986643313a7b already pushed,skipping

Image 1ea210e0e1f6 already pushed,skipping

022aa96f56d0: Image successfully pushed

3369bca87577:Image successfully pushed

73946142ea54:Image successfully pushed

baebdd1b633e:Image successfully pushed

815b7aed2c83:Image successfully pushed

Pushing tag forrev[815b7aed2c83] on {http://10.64.231.45:5000/v1/repositories/s3pics/tags/2.0}

我已经指定了一个tag(2.0),以确保集群中的每个节点都会从Docker Registry获取最新版本。

部署Mesos应用程序


现在,让我们使用Docker镜像部署一个Mesos应用:

POST http://<Mesos Marathon IP>:8080/v2/apps

{"id":"s3pics",

"cmd":"cd /s3pics; ./s3pics -AccessKey=denis@ad.forest -SecretKey=xxxx -EndPoint=http://denisnamespace.ns.viprds.ad.forest -Namespace=denisnamespace",

"cpus":0.1,

"mem":64.0,

"instances":1,

"container":{

     "type":"DOCKER",

     "docker":{

           "image":"10.64.231.45:5000/s3pics:2.0",

           "network":"BRIDGE",

            "portMappings":[{"containerPort":8080,"hostPort":0,"protocol":"tcp"}]

}

},

"healthChecks":[{

"protocol":"HTTP",

"portIndex":0,

"path":"/",

"gracePeriodSeconds":10,

"intervalSeconds":20,

"maxConsecutiveFailures":3}]

}

当Mesos应用程序启动后,Mesos Marathon UI就会显示应用程序的状态。

几秒钟之后,应用部署成功,Docker主机和端口显示在UI中。

上一篇下一篇

猜你喜欢

热点阅读