9đź‘Ť
You’re trying to mount ./data/db
in /var/lib/postgresql/data
and you’re executing docker-compose with a non-privileged user.
So, we can have two possibilities:
- Problem with ./data/db permissions.
- Problem with /var/lib/postgresql/data
The simpiest solution is execute docker-compose with a privileged user (root), but if you don’t want to do that, you can try this:
- Give permissions to ./data/db (I see your EDIT that you’ve already done it).
- Give permissions to /var/lib/postgresql/data
How can you give /var/lib/postgresql/data permissions? Read the following lines:
First, note that /var/lib/postgresql/data is auto-generated by postgre
docker, so, you need to define a new Dockerfile which modifies these
permissions. After that, you need also modify docker-compose to use
this new Dockerfile.
./docker-compose.yml
version: '3'
services:
db:
build:
context: ./mypostgres
dockerfile: Dockerfile_mypostgres
container_name: dummy_project_postgres
volumes:
- ./data/db:/var/lib/postgresql/data
event_planner:
build: ./dumy_project
container_name: dummy_project
volumes:
- .:/web
ports:
- "8000:8000"
depends_on:
- db
links:
- db:postgres
./dumy_project/Dockerfile –> Without changes
./mypostgres/Dockerfile_mypostgres
FROM postgres
RUN mkdir -p /var/lib/postgresql/data
RUN chmod -R 777 /var/lib/postresql/data
ENTRYPOINT docker-entrypoint.sh
17đź‘Ť
I solved by adding “:z” to end of volume defintion
version: '3'
services:
db:
image: postgres
container_name: dummy_project_postgres
volumes:
- ./data/db:/var/lib/postgresql/data:z
event_planner:
build: ./dummy_project
container_name: dummy_project
volumes:
- .:/web
ports:
- "8000:8000"
depends_on:
- db
links:
- db:postgres
What “:z” means
Labeling systems like SELinux require that proper labels are placed on
volume content mounted into a container. Without a label, the security
system might prevent the processes running inside the container from
using the content. By default, Docker does not change the labels set
by the OS.To change the label in the container context, you can add either of
two suffixes :z or :Z to the volume mount. These suffixes tell Docker
to relabel file objects on the shared volumes. The z option tells
Docker that two containers share the volume content. As a result,
Docker labels the content with a shared content label. Shared volume
labels allow all containers to read/write content. The Z option tells
Docker to label the content with a private unshared label. Only the
current container can use a private volume.
- AuthAlreadyAssociated Exception in Django Social Auth
- Can not use celery delay for saved form: object is not JSON serializable
- Django: Uploading multiple files. List of files needed in cleaned_data['file']
- How to throttle Django error emails
1đź‘Ť
This solution is for case that your user
is not present in docker
group.
- First check if your user is in
docker
group:
grep 'docker' /etc/group
- Add user to docker group:
- If the command return is empty, then create
docker
group:
sudo groupadd docker
- Else if your user is not present in command return then add him to the group:
sudo usermod -aG docker $USER
-
Reboot your system
-
Test it again:
docker run hello-world
Tip: Remember to have the docker service started
If it works, try your docker-compose
command again.
- Create UUID on client and save primary key with Django REST Framework and using a POST
- Django – Change a ForeignKey relation to OneToOne
- How can I hide a django label in a custom django form?
- Django Newsletter App
- How to convert request.user into a proxy auth.User class?