简体   繁体   English

docker-compose.yaml 中的命令抛出错误

[英]command in docker-compose.yaml throwing errors

version: "3.4"

services:

  app:
    build:
      context: ./
      target: project_build
    image: sig-project
    environment:
      PROJECT_NAME: "${PROJECT_NAME:-NullProject}"
    command: /bin/bash -c "init_project.sh"
    ports:
      - 7777:7777
    expose:
      - 7777
    volumes:
      - ./$PROJECT_NAME:/app/$PROJECT_NAME
      - .:/home/jovyan/work
    working_dir: /app
    entrypoint: "jupyter notebook --ip=0.0.0.0 --port=7777 --allow-root --no-browser"


Above is my docker-compose.yaml.以上是我的 docker-compose.yaml。

The command doesn't run, I get this error:该命令不运行,我收到此错误:

Unrecognized alias: 'c', it will have no effect

Furthermore, it runs the jupyter notebook out of /bin instead of /app.此外,它从 /bin 而不是 /app 运行 jupyter notebook。

If I change the command to如果我将命令更改为

command: "init_project.sh"

it fails silently, and if try to do something complicated like:它会默默地失败,如果尝试做一些复杂的事情,比如:

command: python init_project.py

then it gives me this:然后它给了我这个:

 No such file or directory: /app/python

note: init_project.sh is just a bash script wrapper for init_project.py注意:init_project.sh 只是 init_project.py 的 bash 脚本包装器

so it seems that for some reason the commands are run in a way that I don't understand and from within the /app directory but without shell or bash.所以似乎由于某种原因,命令以我不理解的方式运行,并且从 /app 目录中运行,但没有 shell 或 bash。

I've been hitting my head against the wall trying to figure out what I'm missing here and I don't know what else to try.我一直在用头撞墙,试图弄清楚我在这里缺少什么,我不知道还能尝试什么。

I've found a variety of issues and discussions that are similar, but nothing seems to resolve it.我发现了各种类似的问题和讨论,但似乎没有任何解决办法。

these are the contents of the working-dir /app:这些是工作目录 /app 的内容:

#ls
Dockerfile  docker-compose.yaml docker_compose.sh  init_project.sh    poetry.lock        pyproject.toml
Makefile    create_poetry_lock.sh  docker_build.sh  init_project.py    install-poetry.py  poetry_lock_update.sh  test.sh

What am I missing?我错过了什么?

Thanks谢谢

Your compose file looks weird to me你的撰写文件对我来说看起来很奇怪

  1. You either have a docker image which container will be created with, or you have a Dockerfile present which builds the image and then container will be created with that image.你要么有一个 docker 镜像,容器将被创建,或者你有一个Dockerfile存在,它构建镜像,然后容器将使用该镜像创建。

Based on what has been said above;根据上面所说的;

Why do you have both image and build attributes on your compose file?为什么您的撰写文件中同时具有imagebuild属性? If image is already available (eg: postgreSQL, rabbitmq) then you don't need to build anything, just provide the image.如果图像已经可用(例如:postgreSQL、rabbitmq)那么您不需要构建任何东西,只需提供图像即可。 If there's no image, then please also add your Dockerfile to the quiestion.如果没有图片,请将您的Dockerfile添加到问题中。

  1. Why are you trying to run /bin/bash -c ?你为什么要运行/bin/bash -c

You can simply add:您可以简单地添加:

bash /path/to/ur/shell_script

Lastly, why don't you add your command in the Dockerfile with CMD ?最后,为什么不将命令添加到DockerfileCMD What are init_project.sh and init_project.py ?什么是init_project.shinit_project.py Maybe also share the content inside those files as well.也许还可以共享这些文件中的内容。 Also might be good to add tree output so we know how from where different commands are being executed.添加tree output 也可能很好,这样我们就知道如何从哪里执行不同的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM