docker-compose文件如下:
version: "3"
services:
backend:
build:
context: .
dockerfile: dockerfile_backend
image: backend:dev1.0.0
entrypoint: ["sh", "-c"]
command: python manage.py runserver
ports:
- "4000:4000"
Run Code Online (Sandbox Code Playgroud)
docker 构建会创建一个文件夹,/docker_container/configs其中包含config.json和 等文件db.sqlite3。将此文件夹安装为卷是必要的,因为在运行时文件夹的内容会被修改或更新,这些更改不应丢失。
我尝试添加卷如下:
volumes:
- /host_path/configs:/docker_container/configs
Run Code Online (Sandbox Code Playgroud)
这里的问题是主机路径(/host_path/configs)的挂载点最初是空的,因此容器映像文件夹(/docker_container/configs)也变空了。这个问题怎么解决呢?
docker dockerfile docker-compose docker-volume persistent-volumes
这是单个 PersistentVolumeClaim 的示例模板,名称为: claim1
apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
name: "claim1"
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "5Gi"
volumeName: "pv0001"
Run Code Online (Sandbox Code Playgroud)
如何在同一个模板文件中添加多个 PersistentVolumeClaim。例如添加 claim2
我尝试从它下面复制粘贴相同的模板并将 claim1 更改为 claim2 但在 openshift UI 中,在导入模板时它给出了一个警告:重复映射键类型:PersistentVolumeClaim
更新:我已经尝试使用---评论中提到的。但这会Expected a single document in the stream but found more在导入 yaml 时在 openshift UI中引发错误
我的docker文件如下:
#Use python 3.6 image
FROM python:3.6
ENV PYTHONUNBUFFERED 1
#install required packages
RUN apt-get update
RUN apt-get install libsasl2-dev libldap2-dev libssl-dev python3-dev psmisc -y
#install a pip package
#Note: This pip package has a completely configured django project in it
RUN pip install <pip-package>
#Run a script
#Note: Here appmanage.py is a file inside the pip installed location(site-packages), but it will be accessible directly without cd to the folder
RUN appmanage.py appconfig appadd.json
#The <pip-packge> installed comes with a …Run Code Online (Sandbox Code Playgroud)