Posts

Showing posts with the label Docker

Fixing Permissions In Docker Container

There are two ways to fix permissions in a docker container. Create User and Group in Container (first way) Dockerfile: FROM ubuntu ARG WWW_USER_UID=1000 ARG WWW_GROUP_GID=1000 RUN addgroup -gid $WWW_GROUP_GID www RUN adduser www \ -uid $WWW_USER_UID \ --disabled-login \ --ingroup www \ --no-create-home \ --quiet \ --system RUN mkdir /app RUN chown www:www /app RUN mkdir /home/www RUN chown www:www /home/www USER www WORKDIR /app WWW_USER_UID and WWW_GROUP_GID must be equal to the user of the host machine, i.e. your current user outside the container. Fix permissions with ACL (second way) Dockerfile: FROM alpine:latest as alpine RUN apk add acl make WORKDIR app CMD ["tail", "-f", "/dev/null"] docker-compose.yaml: version: "3.4" services: alpine: build: context: . target: alpine stop_grace_period: 0s volumes: - .:/app Makefile: fix-permissions: setfacl -dR -m u:$(uid):rwX . setfacl...

How to Store PostgreSQL Data on Host Machine in Docker

In order not to accidentally lose PostgreSQL data, for example, after running the docker system prune -a --volumes command, they can be stored on the host machine, that is, outside docker. # docker-compose.yml version: "3.4" services: database: image: postgres:${POSTGRES_VERSION:-14}-alpine environment: POSTGRES_DB: ${POSTGRES_DB:-app} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!} POSTGRES_USER: ${POSTGRES_USER:-app} volumes: - ./docker/db/data:/var/lib/postgresql/data:rw ports: - 5432:5432 In this case, the docker/db/data directory will store the PostgreSQL data corresponding to the /var/lib/postgresql/data directory in the container. Let's start the container: docker-compose up -d Let's look at the docker/db/data directory: ls -la docker/db/data ls: cannot open directory 'docker/db/data': Permission denied The error occurred because when PostgreSQL starts, it changes the permissions on th...