markshust / docker-magento

Mark Shust's Docker Configuration for Magento
https://m.academy/courses/set-up-magento-2-development-environment-docker/
MIT License
2.56k stars 1k forks source link

bin/download fails, unable to create config.json Permission Denied #447

Closed asheroto closed 3 years ago

asheroto commented 3 years ago

Description Brand new Linux VM, Debian 10, with Docker + Docker-Compose.

Tried entering curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/onelinesetup | bash -s -- magento.test 2.4.2

Failed with below.

Following https://github.com/markshust/docker-magento/blob/master/SETUP.md

Upon entering bin/download 2.3.4

Starting magento_elasticsearch_1 ... done
Starting magento_redis_1         ... done
Starting magento_db_1            ... done
Starting magento_rabbitmq_1      ... done
Creating magento_phpfpm_1        ... done
Creating magento_app_1           ... done

Composer authentication required (repo.magento.com public and private keys):
    Username: <my public key>
    Password: <my private key>

  [ErrorException]
  touch(): Unable to create file /var/www/.composer/config.json because Permission denied

config [-g|--global] [-e|--editor] [-a|--auth] [--unset] [-l|--list] [-f|--file FILE] [--absolute] [--] [<setting-key>] [<setting-value>]...

Composer auth has been setup.
Cannot create cache directory /var/www/.composer/cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /var/www/.composer/cache/files/, or directory is not writable. Proceeding without cache
Cannot create cache directory /var/www/.composer/cache/repo/https---repo.magento.com/, or directory is not writable. Proceeding without cache
Creating a "magento/project-community-edition=2.3.4" project at "./"
Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html

  [Composer\Downloader\TransportException]
  The 'https://repo.magento.com/packages.json' URL required authentication.
  You must be using the interactive console to authenticate

create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--add-repository] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]

Even tried creating /var/www/.composer/config.json and setting its perms to 777 (to test). Still fails.

Tried sudo bin/download 2.3.4 and it still fails. Tried it as root (last hope) and it fails.

Same result with bin/download and bin/download 2.3.0.

Steps To Reproduce See description.

Expected Result Successful install/setup

Actual Result Failed, see description

jjoshm commented 3 years ago

this happens because the ~/.composer folder owner is root. when copied to the container it still has the root owner

simple workaround is to run ./bin/root chown -R app:app /var/www/.composer/ after the failed install and then run your one line install command again

markshust commented 3 years ago

Composer should never be owned by root, on Linux, Mac, or anywhere else. Are you running the curl line as root? If so, you shouldn't be.

asheroto commented 3 years ago

Thank you for your reply.

I'm missing something here, and I too believe it's a permissions issue.

When I run bin/download 2.4.2 it can't find Docker, so I tried sudo bin/download 2.4.2 but also received errors. I am new to Magento but familiar with Linux.

user->~$ bin/download 2.4.2
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
user->~$ sudo bin/download 2.4.2
Stopping user_app_1           ... done
Stopping user_phpfpm_1        ... done
Stopping user_db_1            ... done
Stopping user_rabbitmq_1      ... done
Stopping user_elasticsearch_1 ... done
Stopping user_redis_1         ... done
Starting user_rabbitmq_1      ... done
Starting user_redis_1         ... done
Starting user_elasticsearch_1 ... done
Starting user_db_1            ... done
Starting user_phpfpm_1        ... done
Starting user_app_1           ... done

Composer authentication required (repo.magento.com public and private keys):
    Username: my_api_public_key
    Password: my_api_private_key

Composer auth has been setup.
Creating a "magento/project-community-edition=2.4.2" project at "./"

  [InvalidArgumentException]
  Project directory "/var/www/html/." is not empty.

create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--add-repository] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]

user->~$ ls /var/www
Permissions Size User Group Date Modified    Name
drwxr-xr-x     - user user  2021-04-13 09:04 html

Directory listings w/perms:

user->~$ cd /var/www
user->www$ ls
Permissions Size User Group Date Modified    Name
drwxr-xr-x     - user user  2021-04-13 09:04 html
user->www$ cd html
user->html$ ls
user->html$

Docker output:

user->html$ 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
user->html$ sudo docker ps
CONTAINER ID   IMAGE                                      COMMAND                  CREATED       STATUS         PORTS                                                                                                                                NAMES
cb5a749cdadd   markoshust/magento-nginx:1.18-4            "/docker-entrypoint.…"   4 hours ago   Up 4 minutes   80/tcp, 0.0.0.0:80->8000/tcp, :::80->8000/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp                                               user_app_1
f4313f298bd0   markoshust/magento-php:7.4-fpm-5           "docker-php-entrypoi…"   4 hours ago   Up 4 minutes   9000-9001/tcp                                                                                                                        user_phpfpm_1
8f45e6380dfc   percona:5.7                                "/docker-entrypoint.…"   4 hours ago   Up 4 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp                                                                                            user_db_1
ce4550c73d67   rabbitmq:3.7-management-alpine             "docker-entrypoint.s…"   4 hours ago   Up 4 minutes   4369/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, :::5672->5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, :::15672->15672/tcp   user_rabbitmq_1
6ea341c58aa0   markoshust/magento-elasticsearch:7.7.1-0   "/tini -- /usr/local…"   4 hours ago   Up 4 minutes   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp                                                 user_elasticsearch_1
7f6f7cba4259   redis:5.0-alpine                           "docker-entrypoint.s…"   4 hours ago   Up 4 minutes   6379/tcp                                                                                                                             user_redis_1

I feel like I need to give user access to Docker, right now I can only access docker commands with sudo or as root, of course.

Thanks for your help!

jjoshm commented 3 years ago

I have to correct myself. The folder is not copied, but synced. We should take another closer look. In my case I have two users for example Bob with id 1000 and James with id 1001.

markshust commented 3 years ago

@asheroto this is your error: user->html$ 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

It appears you don't have Docker setup properly, see postinstall commands at https://docs.docker.com/engine/install/linux-postinstall/

asheroto commented 3 years ago

Thank you

katiakweb commented 3 years ago

this happens because the ~/.composer folder owner is root. when copied to the container it still has the root owner

simple workaround is to run ./bin/root chown -R app:app /var/www/.composer/ after the failed install and then run your one line install command again

This was the only thing that make it works. Thanks!

markshust commented 3 years ago

I re-architected how Composer is setup with the Composer 2 support, so perhaps this will help with the above error. https://github.com/markshust/docker-magento/commit/4e029a7c5fedefbf3fb93646a3618e9928fc5656#diff-e819b988ce0448773903f74f99cb7b946fe092468326e2d10054d281cd6890e1L91

But Composer should never be ran as root, ...on the host, in the container, or anywhere else. So this one was user error 🤓

asheroto commented 3 years ago

@markshust haha, indeed. Thanks, I will try this out.

andres-abonia commented 2 years ago

andres@andres-HP-Pavilion-Laptop-14-bk0xx:~/Documentos/Magetnto2$ ./bin/root chown -R app:app /var/www/.composer/ andres@andres-HP-Pavilion-Laptop-14-bk0xx:~/Documentos/Magetnto2$ sudo bin/download 2.4 [sudo] contraseña para andres: Stopping magetnto2_phpfpm_1 ... done Stopping magetnto2_app_1 ... done Stopping magetnto2_rabbitmq_1 ... done Stopping magetnto2_elasticsearch_1 ... done Stopping magetnto2_db_1 ... done Stopping magetnto2_mailcatcher_1 ... done Stopping magetnto2_redis_1 ... done Starting magetnto2_elasticsearch_1 ... done Starting magetnto2_rabbitmq_1 ... done Starting magetnto2_redis_1 ... done Starting magetnto2_phpfpm_1 ... done Starting magetnto2_db_1 ... done Starting magetnto2_mailcatcher_1 ... done Starting magetnto2_app_1 ... done

Composer authentication required (repo.magento.com public and private keys): Username: 88411650cd52e8b831ee41d8c6f8c741 Password: 6fa5c1745e95be45de0be6cd630138d6

Composer auth has been set up. Creating a "magento/project-community-edition=2.4" project at "./" Installing magento/project-community-edition (2.4.0)

andres@andres-HP-Pavilion-Laptop-14-bk0xx:~/Documentos/Magetnto2$

expertsnarensharma commented 2 years ago

this happens because the ~/.composer folder owner is root. when copied to the container it still has the root owner

simple workaround is to run ./bin/root chown -R app:app /var/www/.composer/ after the failed install and then run your one line install command again

bin/fixowns: This will fix filesystem ownerships within the container. i have fixed this by running this docker command

markshust commented 2 years ago

@expertsnarensharma ok good to know this!

jaceksl1 commented 1 year ago

bin/fixowns <- please remember this solved my 6h fighting with this problem...

Hungnguyen999 commented 8 months ago

I found that .composer in /Users/$username/.composer belong to root And i run this cmd sudo chown -R $username .composer change it to be mine. It run like a magic ! Hope it help you

markshust commented 7 months ago

Thanks for the comment @Hungnguyen999. It seems that many devs install Composer as root, but that is very wrong! Your command fixes it to be properly installed.

See https://getcomposer.org/doc/faqs/how-to-install-untrusted-packages-safely.md