I got [Errno 13] Permission denied: './docker-compose.yml' running docker

I installed docker on kubuntu 18 , but I got error

$ docker-compose up -d --build
ERROR: .PermissionError: [Errno 13] Permission denied: './docker-compose.yml'

Reading branch

I tried to salve it :

username@ubuntuOS:/ProjectPath/DOCKER$ sudo groupadd docker
[sudo] password for username:
groupadd: group 'docker' already exists
username@ubuntuOS:/ProjectPath/DOCKER$ sudo gpasswd -a $USER docker
Adding user username to group docker
username@ubuntuOS:/ProjectPath/DOCKER$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

username@ubuntuOS:/ProjectPath/DOCKER$ docker-compose logs -f
ERROR: .PermissionError: [Errno 13] Permission denied: './docker-compose.yml'
username@ubuntuOS:/ProjectPath/DOCKER$ sudo dpkg-reconfigure apparmor
Skipping profile in /etc/apparmor.d/disable: usr.bin.firefox
Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd
username@ubuntuOS:/ProjectPath/DOCKER$ docker-compose up -d --build
ERROR: .PermissionError: [Errno 13] Permission denied: './docker-compose.yml'
username@ubuntuOS:/ProjectPath/DOCKER$ sudo apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.docker.compose
username@ubuntuOS:/ProjectPath/DOCKER$ docker-compose up -d --build
ERROR: .PermissionError: [Errno 13] Permission denied: './docker-compose.yml'

But Failed.

My docker-compose.yml :

version: '3.3'

services:

    web:
        build:
            context: ./           # directory of web/Dockerfile.yml
            dockerfile: Dockerfile.yml


        container_name: lar_nginx_web
        # restart: always
        working_dir: /var/www/
        volumes:
            - ../:/var/www


    nginx:
        image: nginx:1.19-alpine
        container_name: lar_nginx_nginx
        # restart: always
        ports:
            - '8084:80'
        # http://127.0.0.1:8000

        volumes:
            - ../:/var/www
            - ./nginx:/etc/nginx/conf.d

    db:
        container_name: lar_nginx_db
        image: mysql:5.7.28
        # image: mysql:8.0.21
        # restart: always
        environment:
            - MYSQL_DATABASE=DockerLarNginx
            - MYSQL_USER=docker_user
            - MYSQL_PASSWORD=4321
            - MYSQL_ALLOW_EMPTY_PASSWORD=false
            - MYSQL_ROOT_PASSWORD=321
            - TZ=Europe/Kiev

        volumes:
            - /var/lib/mysql

    phpmyadmin:
        container_name: lar_nginx_phpmyadmin
        depends_on:
            - db
        image: phpmyadmin/phpmyadmin
        # restart: always
        ports:
            - 8085:80
        environment:
            PMA_HOST: db
            MYSQL_ROOT_PASSWORD: 1

    composer:
        image: composer:2.1
        container_name: lar_nginx_composer
        volumes:
            - ./:/var/www
        working_dir: /var/www
        command: composer install  --ignore-platform-reqs

Project directory :

$ ls -l
total 16
-rwxrwxrwx 1 root root  940 Sep  5 16:39 BySteps.txt
-rwxrwxrwx 1 root root 1561 Sep  5 16:56 docker-compose.yml
-rwxrwxrwx 1 root root 1094 Sep  5 09:15 Dockerfile.yml
drwxrwxrwx 1 root root    0 Sep  2 08:21 nginx
-rwxrwxrwx 1 root root  805 Oct 20  2019 virtualhost.conf

How can it be fixed ?

Thanks!

You might want to turn off apparmor and check if it works without. If this is the case, you will need to figure out how to permit access for the file - I never had to tinker around with apparmor on Ubuntu.

sudo systemctl stop apparmor
#run your test, then restart apparmor again
sudo systemctl start apparmor

By any chance are you running the Docker package from Snap?

Stopping apparmor I got errors:

username@ubuntuOS:ProjectPath$ sudo systemctl stop apparmor
[sudo] password for serge:
username@ubuntuOS:ProjectPath$ sudo systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker
Failed to enable unit: Unit file /etc/systemd/system/docker.service is masked.
username@ubuntuOS:ProjectPath$ sudo systemctl start docker
Failed to start docker.service: Unit docker.service is masked.
username@ubuntuOS:ProjectPath$ sudo systemctl start apparmor

I installed docker with command :

sudo apt-get install docker-ce

Is it snap installation?

docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info

In which way have I to check is it snap installation and how my errors depends on it ?

I failed to run docker :

$ sudo systemctl enable docker
[sudo] password for serge:
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker

Failed to enable unit: Unit file /etc/systemd/system/docker.service is masked.
$ sudo systemctl start docker
Failed to start docker.service: Unit docker.service is masked.

In my Synaptic I found installed packages:

snap
location of genes from DNA sequence with hidden markov model

and

apparmor
user-space parser utility for AppArmor

I have some prior docker expierence, but I did not have such problems.
How these can be fixed?

When the current user lacks the necessary permissions to access a file or directory. To resolve this issue, you can check the file or directory permissions, ensuring that the user has appropriate read, write, or execute permissions. Verify ownership, making sure the user is the owner or belongs to a group with sufficient permissions. If accessing system files, run the program or script with administrative privileges. Check if the file is currently in use by another process and close any applications that might have it locked. Ensure that the parent directory allows write access if you are creating or modifying a file within it. Antivirus or security software can also restrict access, so temporarily disable or configure it accordingly.