podman exec --env-file 似乎不起作用
podman exec --env-file seemingly not working
尝试运行以下命令:
podman exec -it --env-file=./env/local.env bbss superset fab create-admin \
--username ${BBSS_ADMIN_USERNAME} \
--firstname ${BBSS_ADMIN_FIRSTNAME} \
--lastname ${BBSS_ADMIN_LASTNAME} \
--email ${BBSS_ADMIN_EMAIL} \
--password ${BBSS_ADMIN_PASSWORD}
我的 env 文件如下所示:
BBSS_ADMIN_USERNAME=admin
BBSS_ADMIN_FIRSTNAME=Adam
BBSS_ADMIN_LASTNAME=Adams
BBSS_ADMIN_EMAIL=admin@xxx.com
BBSS_ADMIN_PASSWORD=xxx
但是,我会收到错误消息,指出我的环境变量为空:
Error: Option '--password' requires an argument.
我已经将 --env-file
与 podman run
和相同的 env 文件一起使用,并且工作正常
有什么迹象表明我在这里做错了吗?
请记住,您的 local shell 在执行命令之前解释变量引用。如果你 运行...
podman exec mycontainer somecomand $SOMEVARIABLE
那么$SOMEVARIABLE
的值来自于你本地的shell,而不是容器内部的shell。要使您的命令生效,您需要执行以下操作:
podman exec -it --env-file=./env/local.env bbss sh -c '
superset fab create-admin \
--username ${BBSS_ADMIN_USERNAME} \
--firstname ${BBSS_ADMIN_FIRSTNAME} \
--lastname ${BBSS_ADMIN_LASTNAME} \
--email ${BBSS_ADMIN_EMAIL} \
--password ${BBSS_ADMIN_PASSWORD}
'
在这里,我们使用单引号来禁止本地 shell 的变量扩展,并将整个命令传递给容器中的 shell。
尝试运行以下命令:
podman exec -it --env-file=./env/local.env bbss superset fab create-admin \
--username ${BBSS_ADMIN_USERNAME} \
--firstname ${BBSS_ADMIN_FIRSTNAME} \
--lastname ${BBSS_ADMIN_LASTNAME} \
--email ${BBSS_ADMIN_EMAIL} \
--password ${BBSS_ADMIN_PASSWORD}
我的 env 文件如下所示:
BBSS_ADMIN_USERNAME=admin
BBSS_ADMIN_FIRSTNAME=Adam
BBSS_ADMIN_LASTNAME=Adams
BBSS_ADMIN_EMAIL=admin@xxx.com
BBSS_ADMIN_PASSWORD=xxx
但是,我会收到错误消息,指出我的环境变量为空:
Error: Option '--password' requires an argument.
我已经将 --env-file
与 podman run
和相同的 env 文件一起使用,并且工作正常
有什么迹象表明我在这里做错了吗?
请记住,您的 local shell 在执行命令之前解释变量引用。如果你 运行...
podman exec mycontainer somecomand $SOMEVARIABLE
那么$SOMEVARIABLE
的值来自于你本地的shell,而不是容器内部的shell。要使您的命令生效,您需要执行以下操作:
podman exec -it --env-file=./env/local.env bbss sh -c '
superset fab create-admin \
--username ${BBSS_ADMIN_USERNAME} \
--firstname ${BBSS_ADMIN_FIRSTNAME} \
--lastname ${BBSS_ADMIN_LASTNAME} \
--email ${BBSS_ADMIN_EMAIL} \
--password ${BBSS_ADMIN_PASSWORD}
'
在这里,我们使用单引号来禁止本地 shell 的变量扩展,并将整个命令传递给容器中的 shell。