简体   繁体   中英

docker-compose /bin/sh: 1: path not found

compose currently and I have given a docker-compose file.

version: "3.9"
   
services:
  db:
    image: postgres
    volumes:
      - data-volume:/var/lib/postgresql/data      
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=mimove
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=123
  web:
    image: python:3
    command: /bin/sh -c "/code/scripts/docker-entrypoint.sh"
    volumes:
      - data-volume:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
      
volumes:
    data-volume:

When I use docker-compose up and I got this error. Any ideas?

/bin/sh: 1: /code/scripts/docker-entrypoint.sh: not found

The docker-entrypoint.sh:

cd /code
export PYTHONUNBUFFERED=1
pip install -r requirements.txt
export $(cat etc/environments/development/env)
python manage.py migrate
python manage.py runserver 0.0.0.0:8000

I changed the volumes setting which I didn't it was wrong. Here is the originally docker-compose file. But it also cause an error.

ERROR: for db Cannot start service db: error while creating mount source path '/Volumes/T7/data/psql': mkdir /Volumes: file exists

originally db volumes:

- /Volumes/T7/data/psql:/var/lib/postgresql/data

originally web volumes:

- /Volumes/T7/code/activity-tracker-master:/code

You're hiding your image's /code directory with a named volume. As @JeffRSon notes in a comment, this is the same named volume that's holding your PostgreSQL data, which doesn't really make sense.

I'd split the things you have into that script into three parts: setup that needs to be done in the Docker image

# Dockerfile
FROM python:3.10
WORKDIR /code
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
ENV PYTHONUNBUFFERED=1

# and also
ENTRYPOINT ["./entrypoint.sh"]
CMD ["./manage.py", "runserver", "0.0.0.0:8000"]

The entrypoint wrapper script does the setup that you need to do before running the main command

#!/bin/sh
# entrypoint.sh
export $(cat etc/environments/development/env)
python manage.py migrate
exec "$@"

And then the final line of the entrypoint script runs the image's CMD .

In your docker-compose.yml file, then, you don't need to mount anything into the container or override the command: .

version: '3.8'
services:
  db: { ... } # same as in the question
  web:
    build: .
    # no image: (unless you need to `docker-compose push`)
    # no command: (use the Dockerfile CMD)
    # no volumes: (code is built into the image)
    ports:
      - "8000:8000"
    depends_on:
      - db
      
volumes:
    data-volume: # only used by `db` container

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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