赞
踩
vim /usr/lib/systemd/system/docker.service
服务器防火墙打开2375端口
firewall-cmd --zone=public --add-port 2375/tcp --permanent
firewall-cmd --reload
阿里云开放2375端口
FROM openjdk:8-jdk-alpine
#基于Java环境
VOLUME /tmp
ADD target/app.jar app.jar
#上面target/app.jar和你打包的jar包名字一致,第二个app.jar和下面的/app.jar名字保持一致,为了方便我都使用一样的,这条一定要有,不然做的容器开启不了(到处是坑)
ENTRYPOINT ["java","-jar","/app.jar"]
<!-- 配置全局的属性 --> <properties> <docker.image.prefix>david</docker.image.prefix> </properties> <build> <finalName>app</finalName> <plugins> <!-- 配置SpringBoot的maven插件 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.3.6</version> <configuration> <repository>${docker.image.prefix}/${project.artifactId}</repository> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin> </plugins> </build>
package com.zq.controller;
import com.zq.po.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UserController {
@GetMapping("/demo")
public User demo(){
User user = new User(1,"张三","男",26);
return user;
}
}
User
package com.zq.po; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; @Data @AllArgsConstructor @NoArgsConstructor @ToString public class User { private Integer id; private String name; private String sex; private Integer age; }
Application(SpringBoot启动类不用多说吧)
package com.zq;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
docker images
docker run -d --name docker-server -p 18080:8080 dockerdemo
这里可能有人服务启动不起来,这很可能是jar包的问题
可以执行docker命令查看日志
docker logs -f ee9a3626125b2c625c6de434863dfe4c5a8fd305d08727ad1ee2a4ac35c9e8bc
docker ps -a
firewall-cmd --zone=public --add-port 18080/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all
阿里云控制台那边防火墙也得添加18080/tcp端口规则,我就不再啰嗦了,和之前一样。
好了到此,SpringBoot项目在IDEA上创建镜像部署到阿里云服务器并运行,成功访问已经完成了,欢迎各位在下方收藏+留言反馈。
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。