상황
docker로 Postgres를 실행하려 하는데, 컨테이너 폴더 경로에 권한이 없다는 에러가 뜨면서 종료됨
- docker-compose.yml
version: '3'
services:
db:
image: postgres:latest
container_name: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_USER: "${DB_USER_ID}"
POSTGRES_PASSWORD: "${DB_USER_PASSWORD}"
volumes:
- ./data:/var/lib/postgresql/data
오류 메시지
> docker-compose up
postgres | chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted
postgres | The files belonging to this database system will be owned by user "postgres".
postgres | This user must also own the server process.
postgres |
postgres | The database cluster will be initialized with locale "en_US.utf8".
postgres | The default database encoding has accordingly been set to "UTF8".
postgres | The default text search configuration will be set to "english".
postgres |
postgres | Data page checksums are disabled.
postgres |
postgres | initdb: error: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
postgres | fixing permissions on existing directory /var/lib/postgresql/data ... postgres exited with code 1
해결 과정
강의 커뮤니티에 Postgres 에러 문의 질문이 있었다
Docker desktop을 열어서 기존 컨테이너를 지우라는 답변을 보고 Docker desktop을 들어가 보았는데 다음과 같은 에러가 떴다. 어쩌면 이게 문제인것 같다.

사용자를 Docker 그룹에 추가후 재부팅해보았다. (참고)

하지만 권한 문제가 해결되지 않았고, Docker Desktop 프로그램을 삭제 후 재설치 했더니 정상적으로 실행됨.
이전에 프로그램 설치 후 사용자 계정 권한 바꾸는 일이 있었는데, 그때 꼬인게 아닌가 싶다.
docker가 잘 실행되는 것을 확인 후, 다시 docker-compose up 해보았는데 똑같이 권한 에러가 떴고,
docker desktop 에서는 컨테이너 Status가 Other 이다가 잠깐씩 Running으로 바뀌었다.

더 서치를 해보니 Docker 컨테이너가 Windows 파일 시스템에서 실행될 때 권한 문제가 발생할 수 있다고 했다. 특히 WSL2(Windows Subsystem for Linux) 환경에서는 이런 문제가 자주 발생한다고 한다. 그래서 WSL이 아닌 VSCode 터미널 PowerShell에서 docker-compose up을 해보았는데, 연결 성공



결론
- 실행 터미널 변경으로 문제 해결된 것으로 보아 OS 호환 문제인 것으로 추정
- 트러블 슈팅 소요 시간 : 약 2시간
'Trouble Shooting' 카테고리의 다른 글
AWS EC2 멈춤 현상 (메모리 이슈) (3) | 2024.09.02 |
---|---|
pm2 사용하여 서버 실행 시 net::ERR_SSL_PROTOCOL_ERROR, net::ERR_CONNECTION_RESET 발생 (0) | 2024.09.02 |
CORS 에러 처리 (0) | 2024.06.13 |