Docker

docker, docker-compose 설치 후 Permission denied

thxxyj 2022. 12. 19. 16:37
728x90

docker, docker-compose 설치 방법은 아래 글 참고

 

docker, docker-compose 설치 on Ubuntu

1. docker 설치하기 https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository 1. 패키지 설치 sudo apt-get update sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release 2. GPG key 추가 sudo mkdir -p /etc/apt/keyrings

thxxyj.tistory.com

 

1. Docker 설치 후 Permission denied

docker 설치가 끝난 뒤 docker ps 를 확인했을때 permission denied error 발생하면 docker 그룹에 user를 추가한다.

sudo usermod -aG docker ${USER}

해당 계정으로 재접속하면 permission denied error 없이 docker 사용 가능

user1@my-server:~$ docker -v
Docker version 20.10.22, build 3a2c30b
user1@my-server:~$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied
user1@my-server:~$  sudo usermod -aG docker user1
user1@my-server:~# cat /etc/group | grep docker
docker:x:136:user1

(재접속 후 docker ps 확인)
user1@my-server:~$
docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

 

 

위 명령어로 문제 해결이 안되면 /var/run/docker.sock에 권한 부여한다.

chmod 666 /var/run/docker.sock

user1@my-server:~$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied
user1@my-server:~$ sudo chmod 666 /var/run/docker.sock
user1@my-server:~$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

https://newbedev.com/got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket-at-unix-var-run-docker-sock-get-http-2fvar-2frun-2fdocker-sock-v1-24-containers-json-dial-unix-var-run-docker-sock-connect-permission-denied-docker-code-example

 

 

2. Docker-compose 설치 후 Permission denied

docker-compose 설치가 끝난 뒤 Permission denied error가 발생하면

chmod 755 /usr/local/bin/docker-compose

user1@my-server:~$ docker-compose -v
-bash: /usr/local/bin/docker-compose: Permission denied
user1@my-server:~$  sudo chmod +x /usr/local/bin/docker-compose
user1@my-server:~$ docker-compose -v
Docker Compose version v2.14.0

https://stackoverflow.com/questions/59265190/permission-denied-in-docker-compose-on-linux

728x90