我们可以更改 wso2/wso2mi Docker 镜像中的 Java 版本吗? [英] Can we change the Java version in wso2/wso2mi Docker image?
问题描述
在 nobf0d19027bexprel="2010"wso2/wso2mi Docker 镜像当前使用ENV JAVA_VERSION=jdk-11.0.10+9
,是否可以降级或升级此Java版本?
In wso2/wso2mi Docker image currently using ENV JAVA_VERSION=jdk-11.0.10+9
, is this possible to downgrade or upgrade this Java version?
我为什么要找这个?
我的应用程序中 ENV JAVA_VERSION=jdk-11.0.10+9
遇到一个奇怪的问题,我们的 SOAP 网络服务抛出
I am facing a weird problem with ENV JAVA_VERSION=jdk-11.0.10+9
in my application our SOAP web services throwing
{
"httpCode": 502,
"userMessage": "Invalid response from remote host",
"developerMessage": "The creation time is ahead of the current time.",
"details": {
"detail": "wsse:InvalidSecurityToken"
},
"errorCode": "S:Sender",
"timeStamp": 1624875331996,
"transactionId": "CIP-urn:uuid:b813c0a1-da6a-4dfe-8647-7237f39de941"
}
虽然当我们使用较低 [1.2.0-centos7
] 版本的 wso2/wso2mi
时,相同的代码工作正常,所以我想测试 wso2/wso2mi
与不同的 Java 版本.
While same code is working fine when we are using lower[1.2.0-centos7
] version of wso2/wso2mi
so I want to test wso2/wso2mi
with different Java version .
不确定这段代码是否对不同的 Java 版本做了一些魔法.
Not sure if this code doing some magic for different java version .
private void addSecurityHeader(MessageContext mc, String username, String password) throws Exception {
SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
rand.setSeed(System.currentTimeMillis());
byte[] nonceBytes = new byte[16];
rand.nextBytes(nonceBytes);
String createdDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withZone(ZoneId.of("UTC")).format(Instant.now());
byte[] createdDateBytes = createdDate.getBytes();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
stream.write(nonceBytes);
stream.write(createdDateBytes);
stream.write(password.getBytes(StandardCharsets.UTF_8));
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] passwordDigest = md.digest(stream.toByteArray());
SOAPEnvelope envelope = mc.getEnvelope();
OMFactory factory = envelope.getOMFactory();
OMNamespace securityNamespace = factory.createOMNamespace(
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "wsse");
SOAPHeaderBlock securityBlock = envelope.getHeader().addHeaderBlock("Security", securityNamespace);
securityBlock.setMustUnderstand(true);
OMElement usernameTokenElement = factory.createOMElement("UsernameToken", securityNamespace);
OMNamespace namespaceWSU = factory.createOMNamespace(
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "wsu");
OMAttribute attribute = factory.createOMAttribute("Id", namespaceWSU, "SOAI_req_SOAI");
usernameTokenElement.addAttribute(attribute);
securityBlock.addChild(usernameTokenElement);
OMElement usernameElement = factory.createOMElement("Username", securityNamespace);
usernameElement.setText(username);
usernameTokenElement.addChild(usernameElement);
OMElement passwordElement = factory.createOMElement("Password", securityNamespace);
attribute = factory.createOMAttribute("Type", null,
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
passwordElement.addAttribute(attribute);
passwordElement.setText(new String(Base64.encodeBase64(passwordDigest), StandardCharsets.UTF_8));
usernameTokenElement.addChild(passwordElement);
OMElement nonceElement = factory.createOMElement("Nonce", securityNamespace);
attribute = factory.createOMAttribute("EncodingType", null,
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
nonceElement.addAttribute(attribute);
nonceElement.setText(new String(Base64.encodeBase64(nonceBytes), StandardCharsets.UTF_8));
usernameTokenElement.addChild(nonceElement);
OMElement createdElement = factory.createOMElement("Created", securityNamespace);
createdElement.setText(createdDate);
usernameTokenElement.addChild(createdElement);
}
编辑 1
所以我尝试使用我们自己的 Docker 文件来创建图像,这是内容
So what i tried we are using our own Docker file to create image and here is the contents
FROM wso2/wso2mi:4.0.0
FROM adoptopenjdk/openjdk8:jdk8u232-b09-slim
COPY /lib/* $WSO2_SERVER_HOME/lib/
COPY /carFiles/api_common-20.11.0-SNAPSHOT.car $WSO2_SERVER_HOME/repository/deployment/server/carbonapps/
COPY /carFiles/api_impl-20.11.0-SNAPSHOT.car $WSO2_SERVER_HOME/repository/deployment/server/carbonapps/
COPY /carFiles/api-20.11.0-SNAPSHOT.car $WSO2_SERVER_HOME/repository/deployment/server/carbonapps/
此构建后将用于部署到 Docker+Kubernetes 环境中.
After this build will be use to deploy into the Docker+Kubernetes Environment.
推荐答案
我们无法在运行时更改 Java 版本.因此,我们必须使用所需的 Java 版本构建一个新映像.您可以使用现有的 Dockerfile
并对其进行修改以从头开始构建映像,也可以在 wso2/wso2mi
之上构建新映像并更改 Java 版本在里面.
We can't change the Java version in runtime. Hence, we have to build a new image with the required Java version. You can either use the existing Dockerfile
and modify it to build an image from the scratch or you can build a new image on top of the wso2/wso2mi
and change the Java version in it.
参考,这里 是用于构建 wso2/wso2mi
镜像的 Dockerfile
.
For reference, here is the Dockerfile
used to build the wso2/wso2mi
images.
下面给出了一个示例 Dockerfile
以及用于在本地使用 Java 8 构建映像的步骤
Given below is a sample Dockerfile
and the steps used to build the image with Java 8 locally
更新现有的CentOS
Dockerfile
with Java 8 base image
Update the existing CentOS
Dockerfile
with Java 8 base image
FROM adoptopenjdk/openjdk8:x86_64-centos-jre8u242-b08
下载 wso2mi-4.0.0
并将其放置在 Dockerfile
所在的同一目录中.将 wso2mi-4.0.0
重命名为 wso2mi
Download and place the wso2mi-4.0.0
in the same directory where the Dockerfile
is placed. Rename the wso2mi-4.0.0
to wso2mi
执行以下命令构建镜像
docker build -t <tag-name> . --build-arg MICROESB_VERSION=4.0.0
构建完成后,在本地启动一个容器以验证一切正常.然后,将镜像推送到私有/公共 Docker 存储库,并在 K8s 中引用以拉取它
Once it is built, start a container locally to verify everything is working. Then, push the image to a private/public Docker repository and refer that in the K8s to pull it
docker run -d --name <container-name> <image-name>
此外,您可以执行exec
命令进入容器内部并验证Java版本
Additionally, you can perform the exec
command to go inside the container and verify the Java version
docker exec -it <container-name> sh
当您使用现有的 wso2/wso2mi
镜像构建您自己的镜像时,您可以按照以下类似的方法安装和配置 Java 8.
As you are using the existing wso2/wso2mi
image to build your own image, you can follow a similar approach as following to install and configure the Java 8.
给定的方法从 GitHub 下载 Java 8 二进制文件并配置 JAVA_HOME
和 PATH
环境变量.在下面找到一个示例 Dockerfile
The given approach downloads the Java 8 binary from GitHub and configures the JAVA_HOME
and PATH
environment variables. Find a sample Dockerfile
below
FROM wso2/wso2mi:4.0.0
# FROM adoptopenjdk/openjdk8:jdk8u232-b09-slim
# Perform COPY artifacts
COPY /lib/* $WSO2_SERVER_HOME/lib/
...
# Download and configure Java 8
RUN \
wget -O jdk8.tar.gz https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u292-b10/OpenJDK8U-jdk_x64_linux_hotspot_8u292b10.tar.gz; \
mkdir -p ${WORKING_DIRECTORY}/openjdk-8; \
cd ${WORKING_DIRECTORY}/openjdk-8; \
tar -xf ${WORKING_DIRECTORY}/jdk8.tar.gz --strip-components=1; \
export PATH=${WORKING_DIRECTORY}/openjdk-8/bin:$PATH; \
rm ${WORKING_DIRECTORY}/jdk8.tar.gz;
ENV JAVA_HOME=${WORKING_DIRECTORY}/openjdk-8 \
PATH=${WORKING_DIRECTORY}/openjdk-8/bin:$PATH
这篇关于我们可以更改 wso2/wso2mi Docker 镜像中的 Java 版本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!