我在我的Kubernetes群集上启动了glassfish pod,我试图从我主机上的文件夹中复制一些.war文件,但命令cp似乎总是失败
我的yaml文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: glassfish
spec:
# replicas: 2
selector:
matchLabels:
app: glassfish
strategy:
type: Recreate
template:
metadata:
labels:
app: glassfish
spec:
containers:
- image: glassfish:latest
name: glassfish
ports:
- containerPort: 8080
name: glassfishhttp
- containerPort: 4848
name: glassfishadmin
command: ["/bin/cp"]
args: #["/mnt/apps/*","/usr/local/glassfish4/glassfish/domains/domain1/autodeploy/"]
- /mnt/apps/
- /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/
volumeMounts:
- name: glassfish-persistent-storage
mountPath: /mount
- name: app
mountPath: /mnt/apps
volumes:
- name: glassfish-persistent-storage
persistentVolumeClaim:
claimName: fish-mysql-pvc
- name: app
hostPath:
path: /mnt/nfs
type: Directory

我试图在我的容器中使用以下命令:
cp /mnt/apps/* /usr/local/glassfish4/glassfish/domains/domain1/autodeploy
我做错了什么?
到目前为止,我已尝试使用/ 进行此操作,没有它,使用/ * 当我使用apps / 时,我看到"项目或目录未找到",当我使用apps / i得到"目录省略"时,我只需要在地图中找到什么,而不是地图本身如此 - 也没有真正帮助。
答案 0 :(得分:0)
这里有两点需要注意:
cp
复制版权限,则必须向-a
提供-R
或cp
标记:-R If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. If the source_file ends in a /, the contents of the directory are copied rather than the directory itself. This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process' umask. In -R mode, cp will continue copying even if errors are detected.
如果在pod中使用/bin/cp
作为入口点,则不会在shell中执行此命令。 *
中的/path/to/*
是一个shell功能。
initContainers没有args
,只有`命令。
要使其工作,请改为使用/bin/sh
作为命令:
command:
- /bin/sh
- -c
- cp /mnt/apps/* /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/
答案 1 :(得分:0)
我做错了什么?
这是执行的正确命令:
command: ["sh", "-c", "cp -r /mnt/apps/* /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/ && asadmin start-domain --verbose"]
使用cp命令可以有效地覆盖合法的必需命令来启动所有内容。如果检查该容器,您可以看到原始的(没有您的cp命令运行正常)。最初,容器以:
启动...
"Cmd": [
"/bin/sh",
"-c",
"asadmin start-domain --verbose"
],
...
只需在复制命令解决您的问题后添加它。