I have a Django project that runs in a Docker container within docker-compose.yml with postgresql, pgadmin4 and redis. I have start.sh script that make and run migrations:
start.sh:
#!/bin/bash
# Creating migrations if they are
python manage.py makemigrations
# Apply migrations
python manage.py migrate
After building the image and runing docker-compose up command django project give me an error: exec ./start.sh: no such file or directory but my start.sh file is in the same directory where Dockerfile and docker-compose.yml are. PostgreSQL, pgadmin4 and Redis runs successfully. How to solve this problem? My system is Windows 10.
Dockerfile:
FROM python:3.11.3-alpine
ENV PYTHONBUFFERED=1
WORKDIR /code
COPY requirements.txt .
RUN pip install -r requirements.txt --upgrade
COPY . .
COPY start.sh .
RUN chmod +x start.sh
ENTRYPOINT [ "./start.sh" ]
EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
docker-compose.yml:
services:
api:
image: meduzzen-backend-api
container_name: django
tty: true
stdin_open: true
volumes:
- .:/code
- ./code:/apps
ports:
- "8000:8000"
depends_on:
- postgres-db
- redis
env_file:
- .env
networks:
- api-db-redis
postgres-db:
image: postgres:latest
container_name: postgres_db
ports:
- "5432:5432"
volumes:
- data:/var/lib/postgresql/data
env_file:
- .env
networks:
api-db-redis:
# Have access the database using pgadmin4
ipv4_address: 172.24.0.6
pg-admin:
image: dpage/pgadmin4:latest
container_name: pg_admin
env_file:
- .env
ports:
- "5050:5050"
networks:
- api-db-redis
redis:
image: redis:latest
container_name: redis_cache
ports:
- "6379:6379"
networks:
- api-db-redis
volumes:
data:
networks:
api-db-redis:
ipam:
driver: default
config:
- subnet: 172.24.0.0/24
I've tried to add \r in the end of start.sh instructions.Change file destination in Dockerfile.
Your issue is that you're using an Alpine image and they don't have bash
installed by default.
In the first line of your script, you've indicated that the script should be run using bash
and so it fails.
Change the first line in your script to
#!/bin/sh
and it'll work.
One thing you should be aware of is that Docker only runs a single command when the container starts. When you have both an ENTRYPOINT and a CMD, those are concatenated into a single command. In your case, the command is
./start.sh python3 manage.py runserver 0.0.0.0:8000
I think that you think that they'll be run as two separate commands. They won't.