上下文
目前,我第一次在谷歌云和Kubernetes上上线了Elixir/Phoenix应用程序(我找到了一个教程,我遵循一个教程=>使用谷歌Kubernete引擎在容器中运行Elixir/菲尼克斯应用程序),我陷入了似乎是最后一步的困境:由于一些错误,我没有找到修复方法,部署到集群。
该应用程序
长生不老药应用程序是一个伞形应用程序,有两个phoenix应用程序,每个应用程序都有一个端口(用于管理网站,另一个用于一般网站)和另外三个长生不老剂应用程序。
有一个用于dev的自定义docker(使用docker-compose),还有一个用于production的Dockerfile,它是下面的一个(分为两部分,我猜第一部分用于图像构建,第二部分用于kubernetes):
# prod.Dockerfile
FROM elixir:alpine
ARG app_name=prod
ARG phoenix_subdir=.
ARG build_env=prod
RUN apk add --no-cache make build-base openssl ncurses-libs libgcc libstdc++
ENV MIX_ENV=${build_env} TERM=xterm
WORKDIR /opt/app
RUN apk update
&& apk --no-cache --update add nodejs npm
&& mix local.rebar --force
&& mix local.hex --force
COPY . .
RUN mix do deps.get, compile
RUN cd apps/admin/assets
&& npm rebuild node-sass
&& npm install
&& ./node_modules/webpack/bin/webpack.js
&& cd ..
&& mix phx.digest
RUN cd apps/app/assets
&& npm rebuild node-sass
&& npm install
&& ./node_modules/webpack/bin/webpack.js
&& cd ..
&& mix phx.digest
RUN mix release ${app_name}
&& mv _build/${build_env}/rel/${app_name} /opt/release
&& mv /opt/release/bin/${app_name} /opt/release/bin/start_server
FROM alpine:latest
RUN apk add make build-base --no-cache openssl ncurses-libs libgcc libstdc++
ARG hello
RUN apk update
&& apk add --no-cache postgresql-client
&& apk --no-cache --update add bash ca-certificates openssl-dev
&& mkdir -p /usr/local/bin
&& wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64
-O /usr/local/bin/cloud_sql_proxy
&& chmod +x /usr/local/bin/cloud_sql_proxy
&& mkdir -p /tmp/cloudsql
ENV GCLOUD_PROJECT_ID=${project_id}
REPLACE_OS_VARS=true
EXPOSE ${PORT}
EXPOSE 4011
WORKDIR /opt/app
COPY --from=0 /opt/release .
CMD (/usr/local/bin/cloud_sql_proxy
-projects=${GCLOUD_PROJECT_ID} -dir=/tmp/cloudsql &);
exec /opt/app/bin/start_server start
由cloudbuild.yaml
:调用
steps:
- name: "gcr.io/cloud-builders/docker"
args: ["build", "-t", "gcr.io/hello/prod:$_TAG",
"--build-arg", "project_id=hello", ".",
"--file=./prod.Dockerfile"]
images: ["gcr.io/hello/prod:$_TAG"]
步骤
(重新)构建图像
$> gcloud builds submit --substitutions=_TAG=v1 .
然后创建一个部署
$> kubectl run hello-web --image=gcr.io/${PROJECT_ID}/hello:v1 --port 8080
pod/hello-web created
检查展开是否顺利(扰流板:没有)
$> kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-web 0/1 CrashLoopBackOff 1 15s
检查日志
$> kubectl logs {POD-NAME}
显示以下错误:
错误
2021/08/09 23:49:15 current FDs rlimit set to 1048576, wanted limit is 8500. Nothing to do here.
2021/08/09 23:49:15 gcloud is not in the path and -instances and -projects are empty
Error loading shared library libstdc++.so.6: No such file or directory (needed by /opt/app/erts-12.0.3/bin/beam.smp)
Error loading shared library libgcc_s.so.1: No such file or directory (needed by /opt/app/erts-12.0.3/bin/beam.smp)
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __cxa_begin_catch: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZSt24__throw_out_of_range_fmtPKcz: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _Znwm: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZSt20__throw_length_errorPKc: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __cxa_guard_release: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEm: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __popcountdi2: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZSt17__throw_bad_allocv: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_appendEPKcm: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZSt18_Rb_tree_incrementPKSt18_Rb_tree_node_base: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __cxa_end_catch: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __cxa_guard_acquire: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEmmm: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZSt19__throw_logic_errorPKc: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZSt18_Rb_tree_decrementPSt18_Rb_tree_node_base: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7reserveEm: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __cxa_rethrow: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _Unwind_Resume: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZdlPvm: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZTVN10__cxxabiv120__si_class_type_infoE: symbol not found
...
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZTVN10__cxxabiv120__si_class_type_infoE: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __cxa_pure_virtual: symbol not found
...
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __cxa_pure_virtual: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZTVN10__cxxabiv117__class_type_infoE: symbol not found
...
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZTVN10__cxxabiv117__class_type_infoE: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: _ZTVN10__cxxabiv121__vmi_class_type_infoE: symbol not found
Error relocating /opt/app/erts-12.0.3/bin/beam.smp: __gxx_personality_v0: symbol not found
我试过什么
尽管我几乎一无所知,但我仍然试图对Dockerfile进行一点修改,但没有成功。我还在谷歌上搜索libgcc错误,但没有成功。
仅此而已,因为我没有其他线索可以寻找。
那么,有什么建议可以让它发挥作用吗?
其他行动
删除吊舱,然后获取图像的标签并清除
$> kubectl delete pod hello-web
$> gcloud container images list-tags gcr.io/hello/prod
$> gcloud container images delete gcr.io/hello/prod@sha256:...
编辑
编辑1(2021年8月12日19:04)
- 使用最新版本更新Dockerfile
- 添加另一个操作列表
结果:没有任何变化
看起来你的问题已经在Elixir论坛上被问到了:
https://elixirforum.com/t/docker-run-error-loading-shared-library-libstdc-so-6-and-libgcc-s-so-1/40496
在您的最终映像中,它看起来缺少运行时依赖项。尝试将RUN apk add--no cache openssl ncurses libs更改为RUN apk add--no cache-openssl ncurse libs libstdc++。
修复方法是将libstdc++
添加到您的安装行中。
论坛帖子中也概述了这一点的原因:
beam具有本地运行时依赖项,OTP 24添加了libc作为运行时依赖以支持JIT。有了这个变化,它看起来像是赤裸裸的高山:3.9不再带来所有所需的运行时依赖关系。您需要确保所有这些都存在于应用程序容器中。
祝你好运!
因此,经过数小时的测试和尝试,我只是改变了策略,将重点放在图像版本上,而不是Dockerfile。
$> gcloud builds submit --substitutions=_TAG=v1.1 .
$> kubectl run hello-web --image=gcr.io/${PROJECT_ID}/hello:v1.1 --port 8080
我之前没有更改它,因为我想在构建和应用程序之间保持相同的版本。
我改变的另一件事是cloudbuild.yaml
:我去掉了名字前面的破折号。
这两个动作使构建在pod中运行。