我在 openshift 服务中看不到 Docker 图片

I can't see Docker image in openshift services

我使用这个 Docker 文件创建了 docker 图像:

https://github.com/AdoptOpenJDK/openjdk-docker/blob/master/14/jdk/ubuntu/Dockerfile.hotspot.releases.full

# ------------------------------------------------------------------------------
#               NOTE: THIS DOCKERFILE IS GENERATED VIA "build_latest.sh" or "update_multiarch.sh"
#
#                       PLEASE DO NOT EDIT IT DIRECTLY.
# ------------------------------------------------------------------------------
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM ubuntu:20.04

ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'

RUN apt-get update \
    && apt-get install -y --no-install-recommends tzdata curl ca-certificates fontconfig locales \
    && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
    && locale-gen en_US.UTF-8 \
    && rm -rf /var/lib/apt/lists/*

ENV JAVA_VERSION jdk-14.0.2+12

RUN set -eux; \
    ARCH="$(dpkg --print-architecture)"; \
    case "${ARCH}" in \
       aarch64|arm64) \
         ESUM='ee87e9f03b1fbe6f328429b78fe1a9f44900026d220c90dfd747fe0bcd62d904'; \
         BINARY_URL='https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.2%2B12/OpenJDK14U-jdk_aarch64_linux_hotspot_14.0.2_12.tar.gz'; \
         ;; \
       armhf|armv7l) \
         ESUM='65f193496c6977ba7aed1563edc4b5be091b5ff03e3d790074bb4e389a034b36'; \
         BINARY_URL='https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.2%2B12/OpenJDK14U-jdk_arm_linux_hotspot_14.0.2_12.tar.gz'; \
         ;; \
       ppc64el|ppc64le) \
         ESUM='465a3b8e931896b8d95e452d479615c4bf543535c05b6ea246323ae114e67d7d'; \
         BINARY_URL='https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.2%2B12/OpenJDK14U-jdk_ppc64le_linux_hotspot_14.0.2_12.tar.gz'; \
         ;; \
       s390x) \
         ESUM='7d27aea30e359cf0bb561f8dcca6f4591dbc3ae831981f8a19aa367d31a9709b'; \
         BINARY_URL='https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.2%2B12/OpenJDK14U-jdk_s390x_linux_hotspot_14.0.2_12.tar.gz'; \
         ;; \
       amd64|x86_64) \
         ESUM='7d5ee7e06909b8a99c0d029f512f67b092597aa5b0e78c109bd59405bbfa74fe'; \
         BINARY_URL='https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.2%2B12/OpenJDK14U-jdk_x64_linux_hotspot_14.0.2_12.tar.gz'; \
         ;; \
       *) \
         echo "Unsupported arch: ${ARCH}"; \
         exit 1; \
         ;; \
    esac; \
    curl -LfsSo /tmp/openjdk.tar.gz ${BINARY_URL}; \
    echo "${ESUM} */tmp/openjdk.tar.gz" | sha256sum -c -; \
    mkdir -p /opt/java/openjdk; \
    cd /opt/java/openjdk; \
    tar -xf /tmp/openjdk.tar.gz --strip-components=1; \
    rm -rf /tmp/openjdk.tar.gz;

ENV JAVA_HOME=/opt/java/openjdk \
    PATH="/opt/java/openjdk/bin:$PATH"
CMD ["jshell"]

之后,根据 openshift 中的命令,我已将我的映像推送到 OpenShift Online 集成容器注册表,遵循下面的部分屏幕。

我可以在部署中看到我的容器 运行。

但我在服务中看不到它。

也许有人会知道我的问题的答案。

我做错了什么?

我必须向容器中添加什么才能使其在 openshift 服务中可见?

如果您有任何Docker创建容器的文件,其中 openjdk 14 或 15 出现在 openshift 服务中并且您可以在此处获取它?

A ServicePod 是分开的。因此,您需要单独创建 Service。通常,对于 OpenShift,人们使用 oc new-app 命令行工具 (see the documentation)。这将自动为您创建 Service

如果你想创建一个新的 Service,你可以使用 oc create service 命令行来做到这一点:

oc create service clusterip backend

或者您可以通过在 YAML 中指定 Service 来创建它并使用 oc apply -f <filename>:

应用它
apiVersion: v1
kind: Service
metadata:
  name: backend-service
spec:
  selector:
    app: backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

请注意,您可能需要更改上面的 selectorporttargetPort。作为下一步,通常您希望将服务暴露给外界,这通常是通过 Openshift 中的路由来完成的(oc expose service <service-name> 将为您创建路由)。

What I have to add to the container to make it visible in openshift services?

如上所述,Service 不同于 Pod,因此容器定义与 Service 无关。我建议您 re-create 您的 Pod 使用 oc new-app,这将自动为您创建 Service

感谢您的回答。

我已经尝试使用 quay.io/wildfly/wildfly-runtime-centos7 图像并且成功了。 我假设这张图片在某处有 kind:Service 定义。

容器出现在服务中,下面是我的 Dockerfile 内容。

FROM quay.io/wildfly/wildfly-runtime-centos7:latest
USER root

# install openjdk 14
RUN mkdir /tmp/tools

RUN curl -o /tmp/tools/jdk.tar.gz -L https://download.java.net/openjdk/jdk14/ri/openjdk-14+36_linux-x64_bin.tar.gz && \ 
    tar -zxvf /tmp/tools/jdk.tar.gz -C /tmp/tools

RUN mv /tmp/tools/jdk-14/* /usr/lib/jvm 
RUN rm /tmp/tools/jdk.tar.gz

ENV PATH="/usr/lib/jvm/bin:${PATH}"
ENV JAVA_HOME="/usr/lib/jvm" 

COPY ./target/backend-*-SNAPSHOT.jar /opt/jboss/wildfly/standalone/deployments/backend.jar
CMD ["java", "-jar", "/opt/jboss/wildfly/standalone/deployments/backend.jar"]

我的命令。

构建 docker 图像。

docker build -t backend .

我已经测试过了,运行本地容器。

docker run -it backend

推送到 openshift。

docker tag backend:latest registry.pro-eu-west-1.openshift.com/<MY-PROJECT-NAME>/backend

docker login registry.pro-eu-west-1.openshift.com -u $(oc whoami) -p $(oc whoami -t)

docker push registry.pro-eu-west-1.openshift.com/MY-PROJECT-NAME>/backend