应用程序镜像制作
准备好应用程序
[root@VM_8_24_centos testapp]# ls Dockerfile testapp.tar.gz
编写Dockerfile
[root@VM_8_24_centos testapp]# cat Dockerfile # 基础镜像 FROM core-harbor.minminmsn.com/public/jre-centos:1.8.0_212 # 维护信息 MAINTAINER minyt <minyongtao@minminmsn.com> # 文件复制到镜像 RUN mkdir -p /data1/testapp-app && mkdir -p /data1/logs/testapp-app && mkdir -p /data1/run/testapp-app ADD testapp.tar.gz /data1/testapp-app/ # 设置环境变量 # ENV JAVA_HOME /usr/local/jre1.8.0_212 # ENV PATH ${PATH}:${JAVA_HOME}/bin # 容器启动时运行的命令 CMD ["/data1/testapp-app/bin/launch.sh", "start"] # 暴漏端口 EXPOSE 10030
制作应用程序镜像
[root@VM_8_24_centos testapp]# docker build -t core-harbor.minminmsn.com/public/testapp:2.0 . Sending build context to Docker daemon 58.24MB Step 1/6 : FROM core-harbor.minminmsn.com/public/jre-centos:1.8.0_212 ---> f27d47159f1e Step 2/6 : MAINTAINER minyt <minyongtao@minminmsn.com> ---> Using cache ---> 3d2b8caf725b Step 3/6 : RUN mkdir -p /data1/testapp-app && mkdir -p /data1/logs/testapp-app && mkdir -p /data1/run/testapp-app ---> Running in 8034eb452bfa Removing intermediate container 8034eb452bfa ---> eea12a3c6093 Step 4/6 : ADD testapp.tar.gz /data1/testapp-app/ ---> 1d155c1cd571 Step 5/6 : CMD ["/data1/testapp-app/bin/launch.sh", "start"] ---> Running in c7dab4cffaf9 Removing intermediate container c7dab4cffaf9 ---> 45a1da4c0742 Step 6/6 : EXPOSE 10030 ---> Running in 2618620aa185 Removing intermediate container 2618620aa185 ---> b1d3a82bb34d Successfully built b1d3a82bb34d Successfully tagged core-harbor.minminmsn.com/public/testapp:2.0
本地启动镜像测试
[root@VM_8_24_centos testapp]# docker run -d -p 10030:10030 core-harbor.minminmsn.com/public/testapp:2.0 ce1cf6f8e29554187d8fc810f94e35b80ca0902d0e8fc7d43bc7f5fa5d9a7dc2 [root@VM_8_24_centos testapp]# netstat -tulpn |grep 10030 tcp6 0 0 :::10030 :::* LISTEN 28037/docker-proxy
浏览器访问测试
http://10.2.8.24:10030/ {"returncode":0,"message":"OK"}
上传到私有镜像库
[root@VM_8_24_centos testapp]# docker push core-harbor.minminmsn.com/public/testapp:2.0 The push refers to repository [core-harbor.minminmsn.com/public/testapp] 04b815b81c42: Pushed 8dae5abda95b: Pushed b9049811dc7d: Layer already exists 89169d87dbe2: Layer already exists 2.0: digest: sha256:db7f866ec3f531161c2f6a82667f03896657c34ccaf25b310d519abac175c25e size: 1160 [root@VM_8_24_centos testapp]#
在kubernetes上发布应用
准备testapp.yaml文件
[root@elasticsearch01 testapp]# cat testapp.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: app.kubernetes.io/name: testapp app.kubernetes.io/part-of: ingress-nginx name: testapp namespace: ingress-nginx spec: selector: matchLabels: app.kubernetes.io/name: testapp app.kubernetes.io/part-of: ingress-nginx strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: app.kubernetes.io/name: testapp app.kubernetes.io/part-of: ingress-nginx spec: containers: - image: core-harbor.minminmsn.com/public/testapp:2.0 name: testapp ports: - containerPort: 10030 protocol: TCP restartPolicy: Always volumes: - emptyDir: {} name: data --- apiVersion: v1 kind: Service metadata: name: testapp namespace: ingress-nginx labels: app.kubernetes.io/name: testapp app.kubernetes.io/part-of: ingress-nginx spec: ports: - port: 10030 protocol: TCP targetPort: 10030 selector: app.kubernetes.io/name: testapp app.kubernetes.io/part-of: ingress-nginx type: NodePort --- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: testapp-ingress namespace: ingress-nginx spec: rules: - host: testapp.minminmsn.com http: paths: - path: / backend: serviceName: testapp servicePort: 10030
部署应用
[root@elasticsearch01 testapp]# kubectl create -f testapp.yaml deployment.extensions/testapp created service/testapp created ingress.extensions/testapp-ingress created
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- KVM镜像制作及挂载镜像文件
- 查看Docker镜像仓库中镜像的所有标签
- Android里应用程序,应用程序窗口和视图对象之间的关系
- Vagrant 使用国内镜像安装插件和 box 镜像
- 不要轻易使用 Alpine 镜像来构建 Docker 镜像,有坑!
- Harbor 1.7 发布,在线 GC、镜像历史、镜像复制
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
ACM程序设计培训教程
吴昊 / 中国铁道 / 2007-8 / 28.0
《ACM程序设计培训教程》不是这些专门问题的教科书,所以对这些问题所涉及知识的介绍不多,主要是分析一个个案例,介绍专属于ACM程序设计的方法和技巧。一起来看看 《ACM程序设计培训教程》 这本书的介绍吧!