Jed
Jed

Reputation: 678

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.

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.

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

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.

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:

#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!

Upvotes: 0

Views: 449

Answers (1)

Hossein Heydari
Hossein Heydari

Reputation: 1549

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.

Based on what has been said above;

Why do you have both image and build attributes on your compose file? If image is already available (e.g: postgreSQL, rabbitmq) then you don't need to build anything, just provide the image. If there's no image, then please also add your Dockerfile to the quiestion.

  1. Why are you trying to run /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? What are init_project.sh and init_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.

Upvotes: 1

Related Questions