Docker-Compose服务构建路径找不到
我的应用程序中有一个耙子任务,应该启动TCP服务器。
我已经将rake命令移至 entrypoint.sh
文件,并在docker-compose中添加了新服务,称为 tcp
。
当我运行 docker -compose -d
时,TCP服务返回不正确的路径。我尝试了不同的设置方式,但没有运气。如何为耙子任务构建Docker图像?
unable to prepare context: path "/Users/mac_user/Projects/fmt100/lib/tasks/socketing.rake" not found
docker-compose.yml
version: '3.9'
services:
tcp:
build: ./lib/tasks/socketing.rake
depends_on:
- app
- database
- redis
- sidekiq
env_file: .env
volumes:
- .:/app
- tcp_server:/app/lib/tasks
entrypoint: ./entrypoints/tcp-entrypoint.sh
volumes:
tcp_server:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该拥有
构建:
包含您的导轨应用程序的相同图像。覆盖命令:
运行耙任务。在撰写文件中,它应该大致像:sidekiq
容器看起来非常相似。由于您有两个标记
构建的容器:。
,Compose将尝试两次构建图像。但是,这些图像具有相同的Dockerfiles,并在相同的源树上运行。这意味着Docker的层缓存将生效,第二个构建将非常快速运行,并且实际上不会产生新的图像。为了使这项工作正确,您还需要正确地构建Dockerfile。在这里,您必须将实际命令作为Dockerfile
cmd
而不是entrypoint
(或者至少必须与您在docker-compose.yml )。与往常一样,请确保图像是独立的,并包含其所有库依赖项和应用程序代码(请注意
卷的不存在:
在上面的撰写文件中)。您不应将命令放入
entrypoint
或入口点脚本中。相反,使用入口点进行一些首次设置,也许像Bundler这样的注入相关包装器。命令:
非常简单地覆盖,您提供的任何内容显示在脚本的最终语句中的“ $@”
中。因此,如果您想要一个撬台控制台,则可以在命令行处覆盖
命令:
,而图像的entrypoint
不变。示例组合文件对您的TCP服务器的启动作为耙子任务也相同(而且,我希望您的Sidekiq Worker以相同的方式工作)。You should have it
build:
the same image that contains your Rails application. Override thecommand:
to run the Rake task. In the Compose file it should look roughly like:The
sidekiq
container probably looks very similar.Since you have two containers labeled
build: .
, Compose will try to build the image twice. However, these images have identical Dockerfiles and run on an identical source tree. This means that Docker's layer caching will take effect, and the second build will run extremely quickly and will not actually produce a new image.To make this work correctly, you also need to correctly structure your Dockerfile. It's important here that you put the actual command to run as the Dockerfile
CMD
and not theENTRYPOINT
(or at the very least it must match the override you have in thedocker-compose.yml
). As always, make sure the image is self-contained and includes all of its library dependencies and application code (note the absence ofvolumes:
in the Compose file above).You should not put the command in the
ENTRYPOINT
or an entrypoint script. Instead, use the entrypoint to do some first-time setup, and maybe inject related wrappers like Bundler.The
command:
is very straightforward to override, and whatever you provide appears in the"$@"
in the final statement of the script. So if you want a Pry console, for example, you canwhich will override the
command:
at the command line, leaving the image'sENTRYPOINT
unchanged. The sample Compose file does the same thing for your TCP server launched as a Rake task (and, again, I'd expect your Sidekiq worker to work the same way).