gpt4 book ai didi

docker - 如何准备用于服务器连接的容器?

转载 作者:行者123 更新时间:2023-12-02 19:00:06 26 4
gpt4 key购买 nike

我有一个包含以下内容的Dockerfile:

FROM ubuntu:bionic as builder

ARG DIGITALOCEAN_ACCESS_TOKEN
ARG K8S_CLUSTER
ARG ARGO_SERVER
ARG ARGO_USERNAME
ARG ARGO_PW

RUN apt-get update
RUN apt-get install -y curl

#WORKDIR /app

RUN curl -L https://github.com/digitalocean/doctl/releases/download/v1.41.0/doctl-1.41.0-linux-amd64.tar.gz | tar xz
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
RUN curl -L https://github.com/argoproj/argo-cd/releases/download/v1.4.3/argocd-linux-amd64 -o argocd

RUN chmod +x ./argocd
RUN chmod +x ./kubectl

RUN mv ./argocd /usr/local/bin/
RUN mv ./kubectl /usr/local/bin/
RUN mv ./doctl /usr/local/bin/


CMD doctl auth init -t ${DIGITALOCEAN_ACCESS_TOKEN}; \
doctl kubernetes cluster kubeconfig save ${K8S_CLUSTER}; \
kubectl get svc; \
argocd login ${ARGO_SERVER} --username ${ARGO_USERNAME} --password ${ARGO_PW} --grpc-web; \
argocd context; \
argocd repo list;

ENTRYPOINT ["/usr/local/bin/argocd"]

运行容器:
 docker run --rm -it \                                    
--env=DIGITALOCEAN_ACCESS_TOKEN=c24a7f963ba86e1d38aff12 \
--env=K8S_CLUSTER=k8s \
--env=ARGO_SERVER=argocd.pod.io \
--env=ARGO_USERNAME=user \
--env=ARGO_PW=password \
--name argocd \
argo-cli repo list

表明:
FATA[0000] Argo CD server address unspecified  

与服务器的连接应通过以下命令建立:
CMD doctl auth init -t ${DIGITALOCEAN_ACCESS_TOKEN}; \
doctl kubernetes cluster kubeconfig save ${K8S_CLUSTER}; \
kubectl get svc; \
argocd login ${ARGO_SERVER} --username ${ARGO_USERNAME} --password ${ARGO_PW} --grpc-web; \
argocd context; \
argocd repo list;

我想要实现的是,当我传递参数时,就像我上面对 argo-cli repo list所做的那样,那么应该已经建立了与服务器的连接以获得结果。

最佳答案

运行Docker容器时,您在命令行上提供的任何参数都将覆盖CMD中的参数。
CMD documentation:

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.



要像尝试使用 CMD一样设置服务器,可以创建一个shell脚本来运行setup并在 ENTRYPOINT中运行它。
创建一个具有某些名称的文件,比如 setup_server.sh,其内容为:
#!/usr/bin/env bash
doctl auth init -t ${DIGITALOCEAN_ACCESS_TOKEN}
doctl kubernetes cluster kubeconfig save ${K8S_CLUSTER}
kubectl get svc
argocd login ${ARGO_SERVER} --username ${ARGO_USERNAME} --password ${ARGO_PW} --grpc-web
argocd context
argocd repo list
"$@"
将该文件复制到Dockerfile中:
COPY setup_server.sh /usr/local/bin
并修改 ENTRYPOINT以在 setup_server.sh之前运行 /usr/local/bin/argocd:
ENTRYPOINT setup_server.sh /usr/local/bin/argocd
(所有未经测试)

关于docker - 如何准备用于服务器连接的容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61295844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com