配置远程访问
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| vim /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -H tcp://0.0.0.0:2375
systemctl daemon-reload
systemctl restart docker
|
测试
浏览器访问http://192.168.40.104:2375/verion
idea
安装docker
插件
安装完重启IDEA
配置
Dokcer Api
配置
新建Docker配置,修改主机ip为docker服务器ip,Connection successful表示连接成功
Dockerfile
在根目录新建Dockerfile
1 2 3 4 5
| FROM java:8 VOLUME /tmp COPY target/spring-boot-helloworld-0.0.1-SNAPSHOT.jar demo.jar RUN bash -c "touch /demo.jar" ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-jar", "demo.jar"]
|
docker
插件配置
pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| <docker.image.prefix>valten</docker.image.prefix>
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.2.0</version> <executions> <execution> <id>build-image</id>
<phase>package</phase> <goals> <goal>build</goal> </goals> </execution> </executions> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <imageTags> <imageTag>latest</imageTag> </imageTags> <dockerDirectory>${project.basedir}</dockerDirectory> <dockerHost>http://192.168.40.104:2375</dockerHost> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin>
|
Maven
编译构建
构建镜像
1
| mvn clean package -Dmaven.test.skip=true
|
maven打包的同时就会生成镜像
创建容器
镜像右键新建容器container, Docker->Docker Image,指定镜像ID,容器名和端口映射
运行
测试
http://192.168.40.104:27300/hello
hello world !
HelloWorldController
1 2 3 4 5 6 7 8 9 10 11 12 13
| @RestController public class HelloWorldController {
@RequestMapping("hello") public String sayHello() { return "Hello World !"; }
@RequestMapping("hi") public String sayHi() { return "Hi, EveryBody !"; } }
|
application.properties