为什么 docker-compose 可以工作而 docker run 不能
我有以下 local.yml 文件
version: '3'
services:
celery-worker-default:
image: weapp_app:latest
container_name: weapp_celery-worker-default
command: celery worker -A WeApp -Q default -n default --loglevel=INFO
env_file:
- .env
volumes:
- .:/opt/python/current/app/
当我运行时
docker-compose -f local.yml up celery-worker-default
一切都很好 也像
docker-compose -f local.yml run celery-worker-default celery worker -A WeApp -Q default -n default --loglevel=INFO
Everything run OK
一样运行,但是如果我尝试使用以下命令使用 docker 执行,
docker run -v "$(pwd):/opt/python/current/app/" -w /opt/python/current/app --env-file .env weapp_app:latest celery worker -A WeApp -Q default -n default --loglevel=INFO
我会收到此错误
Error:
Unable to load celery application.
The module "WeApp was not found.
,我已经尝试更改 $(pwd) 为本地完整本地路径,但我收到相同的错误。
以其他方式,我尝试通过命令行使用选项 -e 传递所有环境值并得到相同的错误。 我尝试在 docker 选项中不使用工作目录。 我尝试在容器内打开外壳并执行命令,但出现同样的错误。
I have the following local.yml file
version: '3'
services:
celery-worker-default:
image: weapp_app:latest
container_name: weapp_celery-worker-default
command: celery worker -A WeApp -Q default -n default --loglevel=INFO
env_file:
- .env
volumes:
- .:/opt/python/current/app/
When I run
docker-compose -f local.yml up celery-worker-default
everything work great
also running like
docker-compose -f local.yml run celery-worker-default celery worker -A WeApp -Q default -n default --loglevel=INFO
Everything run OK
But If I try to execute with docker with the following command
docker run -v "$(pwd):/opt/python/current/app/" -w /opt/python/current/app --env-file .env weapp_app:latest celery worker -A WeApp -Q default -n default --loglevel=INFO
I get this error
Error:
Unable to load celery application.
The module "WeApp was not found.
I already try change $(pwd) for the local complete local path but I get the same error.
In other way I try to pass all the environment value by command line with option -e and get the same error.
I try without working directory in the docker options.
I try opening a shell inside the container and execute the command, but the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,感谢所有评论并帮助提出想法的人
在遵循塔伦的评论后,我可以看到问题,但我认为每个人都知道它是件好事。
docker-compose 与 docker 读取环境文件(在我的例子中为 .env)的方式不同。
然后,当您使用 docker-compose 时,您可以声明类似的值
,但对于 docker,您必须声明类似
而不带引号。
这使我的情况变得不同。
再次感谢所有花时间阅读我的帖子的人。
First, Thanks to everybody who commented and help with theirs ideas
After follow Tarun's comment, I could see the problem, but I think is good to everyone know about it.
The environment file (in my case .env) is read in a different way by docker-compose than docker.
Then when you use docker-compose you can declare the values like
But for docker you must have to declare like
without quotation marks.
This made all the difference in my case.
Thanks again to everyone who took a time to read my post.