CF 使用Dockerfile构建开发环境

2019-04-02 11:28 更新

使用Dockerfile快速构建开发环境

在如今容器技术大行其道的世界里, 想比较知名的中间件、代理、开发框架都有自己的容器镜像.


作者为使用者提供了一个最简单的Dockerfile, 方便大家根据实际使用情况修改与发布公有或私有镜像. 同时帮助项目管理者可靠的进行项目内容进行版本管理与发布.

1. 构建本地镜像

如果您还是一个初学者, 在您将cf代码克隆到本地后使用```docker build -t cfweb:v1 .```命令将自动下载并基于centos7构建私有镜像.


这里需要注意的是Dockerfile中间的2条COPY命令, 需要自行下载并且将文件copy到构建目录下. 以防止docker构建时找不到依赖库进行编译.
构建完成后使用docker images命令可以在本地镜像列表内看到cfweb v1版本镜像.

2. 运行私有镜像

如果您仅想测试一下cf! 在上述第二步的时候构建本地镜像完成后即可使用docker run命令运行.

``` docker run -ti -p 8080:8080 cfweb:v1 ```

此时您就可以使用```docker ps | grep cfweb```看到刚刚运行的cfweb容器.

3. 进行测试

在您使用```curl -v localhost:8080/api```后能得到类似返回后. 则说明您构建到镜像构建完成.

[candy@MacBookPro:~/Documents/core_framework] $ curl -v localhost:8080/api
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /api HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 24 Mar 2019 09:56:45 GMT
< Allow: GET, POST, HEAD, OPTIONS
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS
< server: Candy Server/1.0
< Connection: close
< Transfer-Encoding: identity
< Content-Length: 51
< Content-Type: application/json
< Cache-Control: no-cache, no-store, must-revalidate
< Cache-Control: no-cache
<
* Closing connection 0
{"code":200,"message":"This is GET method request"}


[candy@MacBookPro:~/Documents/core_framework]

最后

作者在master分支制作了一个试用镜像推送到dockerhub上, 方便大家快速下载试用. (生产环境请自行制作专属镜像)

[candy@bogon:~/Documents/core_framework] $ docker run -ti -p 8080:8080 candymi/cfweb
Unable to find image 'candymi/cfweb:latest' locally
latest: Pulling from candymi/cfweb
8ba884070f61: Already exists
96bb27abb1c4: Already exists
9b7bcf8be16c: Already exists
aae3ef5368d6: Already exists
12e955618ecc: Already exists
Digest: sha256:6e562228642c56c2162d116b0034d868e9dfb25360248d215d6da8504e26c374
Status: Downloaded newer image for candymi/cfweb:latest
[2019/03/25 07:28:41] - 172.17.0.1 - 172.17.0.1 - /api - 200 - time: 0.000145/Sec

测试容器是否正常运行candy@bogon:~$ curl localhost:8080/api

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号