docker-compose “No such file or directory” for sh-command
docker-compose “No such file or directory” for sh-command
I am setting up docker-for-windows
on my private pc.
docker-for-windows
When I set it up a while ago on my office laptop I had the same issue but it just stopped happening.
So I am stuck with this:
I have a docker-working project (on my other computer) with a docker-compose.yml
like this:
docker-compose.yml
version: '2'
services:
web:
depends_on:
- db
build: .
env_file: ./docker-compose.env
command: bash ./run_web_local.sh
volumes:
- .:/srv/project
ports:
- 8001:8001
links:
- db
- rabbit
restart: always
Dockerfile:
### STAGE 1: Build ###
# We label our stage as 'builder'
FROM node:8-alpine as builder
RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
# build backend
ADD package.json /tmp/package.json
ADD package-lock.json /tmp/package-lock.json
RUN cd /tmp && npm install
RUN mkdir -p /backend-app && cp -a /tmp/node_modules /backend-app
### STAGE 2: Setup ###
FROM python:3
# Install Python dependencies
COPY requirements.txt /tmp/requirements.txt
RUN pip3 install -U pip
RUN pip3 install --no-cache-dir -r /tmp/requirements.txt
# Set env variables used in this Dockerfile (add a unique prefix, such as DOCKYARD)
# Local directory with project source
ENV PROJECT_SRC=.
# Directory in container for all project files
ENV PROJECT_SRVHOME=/srv
# Directory in container for project source files
ENV PROJECT_SRVPROJ=/srv/project
# Create application subdirectories
WORKDIR $PROJECT_SRVPROJ
RUN mkdir media static staticfiles logs
# make folders available for other containers
VOLUME ["$PROJECT_SRVHOME/media/", "$PROJECT_SRVHOME/logs/"]
# Copy application source code to SRCDIR
COPY $PROJECT_SRC $PROJECT_SRVPROJ
COPY --from=builder /backend-app/node_modules $PROJECT_SRVPROJ/node_modules
# Copy entrypoint script into the image
WORKDIR $PROJECT_SRVPROJ
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
CMD ["./run_web.sh"]
docker-compose.env:
C_FORCE_ROOT=True
DJANGO_CELERY_BROKER_URL=amqp://admin:mypass@rabbit:5672//
DJANGO_DATABASE_ENGINE=django.db.backends.mysql
DJANGO_DATABASE_NAME=project-db
DJANGO_DATABASE_USER=project-user
DJANGO_DATABASE_PASSWORD=mypassword
DJANGO_DATABASE_HOST=db
DJANGO_ALLOWED_HOSTS=127.0.0.1,localhost
DJANGO_DEBUG=True
DJANGO_USE_DEBUG_TOOLBAR=off
DJANGO_TEST_RUN=off
PYTHONUNBUFFERED=0
run_web_local.sh:
#!/bin/bash
echo django shell commands
python ./manage.py migrate
echo Starting django server on 127.0.0.1:8000
python ./manage.py runserver 127.0.0.1:8000
When I call docker-compose up web
I get the following error:
docker-compose up web
web_1 | bash: ./run_web_local.sh: No such file or directory
bash run_web_local.sh
bash
command
docker-compose
And: The exact same setup works on my other laptop.
Any ideas? All the two million github posts didn't solve the problem for me.
Thanks!
Update
Removing volumes:
from the docker-compose makes it work like stated here but I don't have an instant mapping. That's kind of important for me...
volumes:
Sorry, it's a company project so it's not an open repo :( But I tried it with several projects, all have the same issue and all of them work on my other pc.
– Ron
Jun 30 at 9:52
Isn't that meant to be ’bash -c ./XXX.sh’? Emphasis on "-c"
– spender
Jun 30 at 9:55
bash -c ./run_web_local.sh
doesn't change it. Same error.– Ron
Jun 30 at 9:57
bash -c ./run_web_local.sh
so, instead try
cat ./run_web_local.sh
or ls ./
and see if things really are as they seem.– spender
Jun 30 at 11:04
cat ./run_web_local.sh
ls ./
2 Answers
2
It may be because the bash file is not in the root path or in the root path of workdir.
Check where is it in the container and verify if the path is correct.
Path is correct. Locally it's on the same level as the
docker-compose.yml
. I changed the path to the containers path but didn't work as well.– Ron
Jun 30 at 9:31
docker-compose.yml
in the Dockerfile is specify the
WORKDIR /srv/project
?– Riccardo Degan
Jun 30 at 9:35
WORKDIR /srv/project
Yes,
WORKDIR /srv/project
– Ron
Jun 30 at 9:51
WORKDIR /srv/project
If possible can you please provide all the files related to this, so that i can try to reproduce the issue.
Seems like command is not executing is the dir where run_web_local.sh exist.
You can check the current workdir by replacing command in docker-compose.yml as command: pwd && bash ./run_web_local.sh
command: pwd && bash ./run_web_local.sh
Great idea! Unfortunately the
pwd
shows /srv/project
so this is correct. What file do you need?– Ron
Jun 30 at 9:50
pwd
/srv/project
Dockerfile you are building, env file and sh file.
– Rohit Jindal
Jun 30 at 10:07
I updated my post
– Ron
Jun 30 at 10:36
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you share github repo if you have?
– Shankar Shastri
Jun 30 at 9:44