DOCKER COPY 未反映在容器中
Dockerfile 不会从 gitlab 目录复制文件。下面是dockerfile,
FROM docker.elastic.co/logstash/logstash:7.16.3
USER root
RUN yum install -y curl dos2unix
COPY scripts/somefile.sh /src/app/
RUN dos2unix /src/app/somefile.sh
WORKDIR /src/app/
ENTRYPOINT ["/src/app/somefile.sh"]
项目树如下所示,
C:.
├───.idea
│ └───codeStyles
├───deployment
│ ├───dev
└───scripts
│ ├───somefile.sh
下面是deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: demo-app
name: demo-app
namespace: --
spec:
replicas: 1
selector:
matchLabels:
app: demo-app
template:
metadata:
labels:
app: demo-app
spec:
containers:
- image: docker-image-described
name: demo-app
resources: ...
volumeMounts:
- name: some-secret
mountPath: /src/abc/secret
readOnly: true
securityContext:
privileged: true
restartPolicy: Always
volumes:
- name: very-secret
secret:
secretName: some-secret
此外,使用gitlab-ci文件构建图像。然后使用该映像创建部署。请帮助我理解我做错了什么,因为当我在正在运行的 Pod 中执行时,我看不到定义的目标位置中的文件。
我没有收到任何错误,如果出现有关错误源位置的错误,我通常会这样做。我也确实遇到了一些类似的问题,所以我已经检查过 EOL 是 Unix。
另外,我想添加一些观察结果,
- 我也无法使用 RUN mkdir -p /src/app/scripts/ 来创建目录,这也可以正常运行,没有任何错误,只是不 反映在吊舱内。
Dockerfile does not copy file from gitlab directory. Below is the dockerfile,
FROM docker.elastic.co/logstash/logstash:7.16.3
USER root
RUN yum install -y curl dos2unix
COPY scripts/somefile.sh /src/app/
RUN dos2unix /src/app/somefile.sh
WORKDIR /src/app/
ENTRYPOINT ["/src/app/somefile.sh"]
The Project tree looks like the following,
C:.
├───.idea
│ └───codeStyles
├───deployment
│ ├───dev
└───scripts
│ ├───somefile.sh
below is deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: demo-app
name: demo-app
namespace: --
spec:
replicas: 1
selector:
matchLabels:
app: demo-app
template:
metadata:
labels:
app: demo-app
spec:
containers:
- image: docker-image-described
name: demo-app
resources: ...
volumeMounts:
- name: some-secret
mountPath: /src/abc/secret
readOnly: true
securityContext:
privileged: true
restartPolicy: Always
volumes:
- name: very-secret
secret:
secretName: some-secret
Further, building the image using gitlab-ci file. And then creating a deployment using this image. Please help me understand what am I doing wrong as when I exec inside the running pod, I can't see the file in the defined destination location.
I don't get any errors, which I usually do if there is an error about wrong source location. I also did go through some more similar questions, so I already checked that the EOL is Unix.
Also, I would like to add some observations,
- I cannot create the directory as well with
RUN mkdir -p /src/app/scripts/
This also runs without any error, just not
reflected inside the pod.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是由于使用了旧的(错误)docker映像,因此不反映更改或更新。
如果图像标签不是“最新”,则Kubernetes如果已经存在图像,则不会提取新的图像版本。通过将图像拉动并用Docker在本地运行,验证图像是否正确构建。使用其他标签迫使Kubernetes拉图像。
This is probably due to using an old (wrong) docker image, so changes or updates are not reflected.
Kubernetes does not pull a new image version if the image is already present if the image tag is not "latest". Verify that the image is correctly build by pulling it and running it locally with docker. Use a different tag to force kubernetes to pull the image.