我想eureka-server
作为容器运行,并希望稍后让其他微服务注册到此容器。但是我遇到了一些问题,让它作为容器运行并访问它。该应用程序在 STS 中运行没有问题。当我在 STS 中执行它时,我可以访问eureka-server
using localhost:8761
.
application.java:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
application.yml:
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
Run Code Online (Sandbox Code Playgroud)
bootstrap.yml:
spring:
application:
name: eureka-service
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM java:8
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-
jar","/app.jar"]
Run Code Online (Sandbox Code Playgroud)
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<docker.image.prefix>microservice</docker.image.prefix>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<groupId>com.example</groupId> …
Run Code Online (Sandbox Code Playgroud) 我尝试使用host:192.168.99.100
和port 在附加模式下远程调试应用程序5005
,但它告诉我它是unable to open the debugger port
。IP是192.268.99.100
(群集通过minikube在本地托管)。
输出 kubectl describe service catalogservice
Name: catalogservice
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=catalogservice
Type: NodePort
IP: 10.98.238.198
Port: web 31003/TCP
TargetPort: 8080/TCP
NodePort: web 31003/TCP
Endpoints: 172.17.0.6:8080
Port: debug 5005/TCP
TargetPort: 5005/TCP
NodePort: debug 32003/TCP
Endpoints: 172.17.0.6:5005
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
Run Code Online (Sandbox Code Playgroud)
这是pods service.yml:
apiVersion: v1
kind: Service
metadata:
name: catalogservice
spec:
type: NodePort
selector:
app: catalogservice
ports:
- …
Run Code Online (Sandbox Code Playgroud) 目前我得到了这个代码:
@GetMapping("/all/")
public Iterable<Article> getAllArticle(){
ArrayList<ArticleEntity> articleEntities = Lists.newArrayList(articleProviderComponent.getAllArticle());
ArrayList<Article> articles = Lists.newArrayList();
for(ArticleEntity articleEntity : articleEntities){
articles.add(ArticleMapper.articleEntity2Article(articleEntity));
}
return articles;
}
Run Code Online (Sandbox Code Playgroud)
存储库返回一个Iterable
,我想转换为ArrayList
.除此之外,我想将每个转换Entity
成一个POJO
.
我尝试使用类似的
list.foreach(ArticleMapper::ArticleMapper.articleEntity2Article)
工作正常,但不返回新的列表.
我还不太了解 dockerhub。我得到了以下案例:
docker tag myimageA myuser/myrepo:1
码头工人标签 myimageB myuser/myrepo:1
码头工人标签 myimageC myuser/myrepo:1
之后我推他们 docker push myuser/myrepo
现在,当删除我所有的本地图像并再次拉出我自己的 docker repo 时,当我执行时将只有一个条目docker images
:
myuser/myrepo
Run Code Online (Sandbox Code Playgroud)
我希望能够将单个图像推送到 docker hub。除此之外,我只能查看我推送的标签(最新、1 或其他)。
问题:会docker push
推送所有标记为 repo 命名空间的图像吗?或者有没有办法将单个图像推送到存储库并一个一个地拉取它们?
执行控制器方法时,我收到此日志:
对象:[字段“名称”上的对象“目录”中的字段错误:拒绝值 [ safasf ];代码 [Pattern.catalog.name,Pattern.name,Pattern.java.lang.String,Pattern]; 参数 [org.springframework.context.support.DefaultMessageSourceResolvable: 代码 [catalog.name,name]; 参数 []; 默认消息 [名称],[Ljavax.validation.constraints.Pattern$Flag;@5f32f731,org.springframework.validation.beanvalidation.SpringValidatorAdapter$ResolvableAttribute@2180fe7e]; 默认消息 [muss auf Ausdruck " [A-Za-z] " passen]]
正则表达式:[A-Za-z]
输入:safasf
编码:
...
@NotNull
@Size(min=1, max=8)
@Pattern(regexp = "[A-Za-z]")
private String name;
...
Run Code Online (Sandbox Code Playgroud)
控制器:
@PostMapping(ADD_CATALOG)
public String addCatalog(@Valid @ModelAttribute Catalog catalog, BindingResult result){
if(result.hasErrors()){
logAction("addCatalog", "Validation of "+catalog.getName()+" failed: ", result.getAllErrors().toString());
return "redirect:/catalog/addCatalog/";
}
catalogProviderComponent.addOrUpdateCatalogEntity(catalogComponent.catalog2catalogEntity(catalog));
logAction("addCatalog","catalog", catalog);
return "redirect:/catalog/addCatalog/";
}
Run Code Online (Sandbox Code Playgroud)
当我去的时候regex101.com
一切似乎都很好。除此之外,我尝试了一些正则表达式,但似乎没有一个正常工作。
所以我已经有了dockerhub
可以使用的图像,因为我已经在服务器上设置了一个 kubernetes 集群。我的下一步是使用 docker swarm 实现类似的功能。我真的不知道如何开始,所以我在这里问。
kubernetes 集群在 a 上运行,bare metal ubuntu VPS server
如下所示:
我的问题是:
如何在
bare metal ubuntu VPS
. 我没有发现太多,是否有任何需要注意的重大更改(类似于metalLB
kubernetes 集群中的更改)?
让我们说我得到了这段代码:
public class Incrementor {
private int i;
public int getInt(){
return i;
}
private void incrementA(){
i = i+1;
}
private void incrementB(){
i = i++;
}
}
Run Code Online (Sandbox Code Playgroud)
incrementA()
之前调用getInt()
该值时将为1.incrementB()
之前调用getInt()
该值时将为0.docker ×4
java ×3
kubernetes ×2
docker-swarm ×1
dockerhub ×1
java-stream ×1
netflix ×1
regex ×1
spring ×1
spring-boot ×1
validation ×1