您当前的位置:首页 > 互联网教程

如何使用Docker 进行Java 开发

发布时间:2025-05-24 16:31:58    发布人:远客网络

如何使用Docker 进行Java 开发

一、如何使用Docker 进行Java 开发

1、java项目开发,假定已有一个java项目能够编译成jar/war并且运行了。

2、编写dockerfile,docker是一个容器技术每一个容器就是一个“完整”的linux系统,这个dockerfile需要提供这个系统包含内容的描述,比如FROM maven:3.3.3、FROM ubuntu:16.04。如果这个java项目是个web项目那么还需要提供tomcat环境。添加项目构建信息。比如采用maven编译项目的话该如何如何。

RUNcd/tmp/build&&mvn-qdependency:resolve

#构建应用RUNcd/tmp/build&&mvn-q-DskipTests=truepackage\

&&rm-rf$CATALINA_HOME/webapps/*\

&&mvtarget/*.war$CATALINA_HOME/webapps/ROOT.war\

&&cd/&&rm-rf/tmp/build

3、暴漏接口:EXPOSE 8080

dockerbuild-tdocker-demo-java-tomcat.

5、基于创建好的镜像创建容器

dockerrun-d-p8080:8080docker-demo-java-tomcat

6、访问

来源于dockercloud文档,可自去查看。

来源于dockercloud文档,可自去查看。

二、php curl的几种用法

总结一下项目中用到curl的几种方式 1. php curl的默认调用方法,get方式访问url$ch= curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER,$header);//设置http头 curl_setopt($ch, CURLOPT_ENCODING,"gzip");//设置为客户端支持gzip压缩 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);//设置连接等待时间 curl_setopt($ch, CURLOPT_URL,$url); curl_exec($ch); if($error= curl_error($ch)){//出错处理return-1;}fclose($fp);$curl_code= curl_getinfo($ch, CURLINFO_HTTP_CODE);//获取http返回值 if($curl_code== 200){//正常访问url}//异常 2.设置http header支持curl访问lighttpd服务器Java代码$header[]='Expect:';$header[]='Expect:'; 3.设置curl,只获取http header,不获取body:Java代码curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1);或者只获取body:Java代码curl_setopt($ch, CURLOPT_HEADER, 0);// make sure we get the body curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_HEADER, 0);// make sure we get the body curl_setopt($ch, CURLOPT_NOBODY, 0); 4.访问虚拟主机,需设置Host$header[]='Host:'.$host; 5.使用post, put, delete等REStful方式访问urlpost:curl_setopt($ch, CURLOPT_POST, 1); put, delete: curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"DELETE");//或者PUT,需要服务器支持这些方法。6.保存下载内容为文件

三、php curl get内容多大

总结一下项目中用到curl的几种方式

1. php curl的默认调用方法,get方式访问url

curl_setopt($ch, CURLOPT_HTTPHEADER,$header);//设置http头

curl_setopt($ch, CURLOPT_ENCODING,"gzip");//设置为客户端支持gzip压缩

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);//设置连接等待时间

curl_setopt($ch, CURLOPT_URL,$url);

if($error= curl_error($ch)){//出错处理return-1;}fclose($fp);

$curl_code= curl_getinfo($ch, CURLINFO_HTTP_CODE);//获取http返回值

2.设置http header支持curl访问lighttpd服务器Java代码$header[]='Expect:';

3.设置curl,只获取http header,不获取body:Java代码curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_NOBODY, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_NOBODY, 1);

或者只获取body:Java代码curl_setopt($ch, CURLOPT_HEADER, 0);// make sure we get the body

curl_setopt($ch, CURLOPT_NOBODY, 0);

curl_setopt($ch, CURLOPT_HEADER, 0);// make sure we get the body

curl_setopt($ch, CURLOPT_NOBODY, 0);

$header[]='Host:'.$host;

5.使用post, put, delete等REStful方式访问urlpost:curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"DELETE");//或者PUT,需要服务器支持这些方法。6.保存下载内容为文件