Reputation: 138
There is a back.Dockerfile.
FROM python:3.9
WORKDIR /src
COPY . ./
RUN apt-get update -y
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
RUN chmod +x boot.sh
ENTRYPOINT ["./boot.sh"]
There is a boot.sh in which I do migrations for Django and then start the service.
#!/bin/sh
while true; do
python /src/manage.py migrate
if [[ "$?" == "0" ]]; then
break
fi
echo Upgrade command failed, retrying in 5 secs...
sleep 5
done
exec python /src/manage.py runserver 0.0.0.0:8000
There is a docker-compose.
version: "3"
services:
backend:
build:
context: .
dockerfile: deploy/back.Dockerfile
volumes:
- .:/src
ports:
- 8888:8000
depends_on:
- db
db:
image: mysql:8.0.24
ports:
- '3307:3306'
environment:
MYSQL_DATABASE: ${MYSQL_NAME}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASS}
MYSQL_ROOT_PASSWORD: ${MYSQL_NAME}
volumes:
- /var/lib/vennepriser-db:/var/lib/mysql
When I run sudo docker-compose up
, I get the error
Tried also such options
ENTRYPOINT ["./boot.sh"]
ENTRYPOINT ["/src/boot.sh"]
How can I fix it?
Upvotes: 0
Views: 1916
Reputation: 158908
Delete the volumes:
block of the docker-compose.yml
file inside the backend
container.
When you have a volumes:
block that injects host-system code into a container like this, it completely replaces whatever content was in the corresponding path in the image. If you make changes to the image filesystem in the Dockerfile (like RUN chmod
) but then mount something over it, those changes will be hidden.
A typical motivation for this sort of setup is to do active development on the code in a container setup. You can use a hybrid Docker/host setup for this: use Compose to start dependencies like the database, but use an ordinary host development environment (e.g., a Python virtual environment) to build the code. You'll need to make sure you have a reasonable configuration system to adjust things like the database location, which will be different in the different environments (localhost:3307
in host-based development, db:3306
in the pure-container environment).
Upvotes: 1