我正在为一个朋友发帖。他请求我的帮助,我们无法知道发生了什么事。
我的情况是:当我的应用程序不在容器中时,我的应用程序可以在Ubuntu 18.04上完美运行,但是客户需要使用容器,因此我创建了一个Dockerfile,以便可以由Docker容器启动它。 这是我的Dockerfile的内容
package countAnagrams;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class TestClass {
public static int check_For_Missing_Characters(String a1, String b1){
int first_String_Length = a1.length();
int missing_Characters = 0;
for( int y = 0; y < first_String_Length; y++ ){
final char character_To_Check_String = a1.charAt(y);
if ( b1.chars().filter(ch -> ch ==
character_To_Check_String).count() == 0 ){
missing_Characters+=1;
}
}
return missing_Characters;
}
public static int check_For_Duplicate_Characters(String a1, String
b1){
int first_String_Length = a1.length();
int duplicat_Characters = 0;
String found_Characters = "";
for( int y = 0; y < first_String_Length; y++ ){
final char current_Character_To_Check = a1.charAt(y);
long first_String_Count = b1.chars().filter(ch -> ch ==
current_Character_To_Check).count();
long second_String_Count = a1.chars().filter(ch -> ch ==
current_Character_To_Check).count();
long found_String_Count = found_Characters.chars().filter(ch -> ch == current_Character_To_Check).count();
if ( first_String_Count > 0 && second_String_Count > 0 && found_String_Count == 0 ){
duplicat_Characters+=Math.abs(first_String_Count - second_String_Count);
found_Characters = found_Characters +
current_Character_To_Check;
}
}
return duplicat_Characters;
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test_Case_Count = Integer.parseInt(br.readLine()); //
Reading input from STDIN
for(int x = 0; x < test_Case_Count; x++ ){
int total_Count_Of_Diff_Chars = 0;
StringBuilder first_StringBuilder = new StringBuilder();
int first_String = '0';
while(( first_String = br.read()) != -1 ) {
first_StringBuilder.append((char) first_String );
}
StringBuilder second_StringBuilder = new StringBuilder();
String second_String = "";
while((( second_String = br.readLine()) != null )){
second_StringBuilder.append(second_String);
}
total_Count_Of_Diff_Chars = total_Count_Of_Diff_Chars +
check_For_Missing_Characters(first_StringBuilder.toString(),
second_StringBuilder.toString());
total_Count_Of_Diff_Chars = total_Count_Of_Diff_Chars +
check_For_Missing_Characters(second_StringBuilder.toString(),
first_StringBuilder.toString());
total_Count_Of_Diff_Chars = total_Count_Of_Diff_Chars +
check_For_Duplicate_Characters(second_StringBuilder.toString(),
first_StringBuilder.toString());
System.out.println(total_Count_Of_Diff_Chars);
}
br.close();
}
}
构建映像后,我执行以下Docker run命令: sudo docker run --name backend-api -p 6543:6543 -d backend / backendapi1.0
我已经在nginx中创建了一条规则,以从端口90重定向到6543(在使用以前可以使用的容器之前)
FROM node:8.9.4
ENV HOME=/home/backend
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev
RUN apt-get install -y npm
COPY . $HOME/
WORKDIR $HOME/
RUN npm rebuild node-sass
RUN npm install --global babel-cli
USER root
EXPOSE 6543
CMD ["babel-node", "index.js"]
P.S .:我尝试将localhost从容器的IP更改为IP,但效果也不佳。 有趣的事实是,当我在6543上尝试使用内部telnet时,它将接受连接并立即将其关闭。
P.S .:防火墙上的所有端口都是打开的。 该应用程序可以在容器外部正常工作(使用端口6543并在nginx中重定向)
如果有人能帮助我们找出发生这种情况的原因,我将不胜感激。我们在创建容器方面经验不足。 非常感谢!
答案 0 :(得分:0)
我们找到了解决方案!! 这是一个Internar容器路由器问题...
以下Docker run命令解决了该问题:
sudo docker run --name my_container_name --network =“ host” -e MONGODB = my_container_ip -p 6543:6543 my_dockerhub_image_name
非常感谢!