Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with .env file inside docker #619

Closed
lk77 opened this issue Jun 5, 2020 · 7 comments
Closed

Issue with .env file inside docker #619

lk77 opened this issue Jun 5, 2020 · 7 comments
Labels
complexity/high This task has a high complexity level docker Things related to docker

Comments

@lk77
Copy link

lk77 commented Jun 5, 2020

Hello i have an issue with .env file inside docker

  • Problem:

.env file is not populated inside docker container and contain only default values for common laravel env variables.

  • Expected:

.env file inside docker container reflects .env file used with docker-compose.yml

  • Logs / Screenshots / Proof:
/var/www/seat # su - www-data -s /bin/sh
dd263f298e14:~$ cd /var/www/seat
dd263f298e14:/var/www/seat$ php artisan

In AbstractConnection.php line 155:

  Connection refused [tcp://127.0.0.1:6379

when switching to www-data, env was lost, and since .env file is not correct,
www-data user is not working, only root has correct env, set in user env.

  • Version Info: PHP Version, SeAT Version, Operating System etc.

Checking Local and Github Versions. Please wait...
+---------------+---------------+---------------+
| Package Name | Local Version | Latest Github |
+---------------+---------------+---------------+
| Api | 3.0.8 | 3.0.8 |
| Console | 3.0.5 | 3.0.5 |
| Eveapi | 3.0.20 | 3.0.20 |
| Notifications | 3.0.6 | 3.0.6 |
| Web | 3.0.28 | 3.0.28 |
| Services | 3.0.11 | 3.0.11 |
+---------------+---------------+---------------+

For now i've done a printenv > .env,

it works but i contain env variables out of scope, like php env variables,
and it's not escaped correctly, i had to manually correct it.

thanks.
nb : i have the issue with app image, but perhaps the others aswell.

@warlof warlof added the docker Things related to docker label Jun 6, 2020
@warlof
Copy link
Member

warlof commented Jun 9, 2020

Indead, the file isn't touch in docker environment, we're using environnement variables only.

Why do you need to change user inside the container?

@warlof
Copy link
Member

warlof commented Oct 25, 2020

Is it still relevant with new SeAT 4 Docker image ?

@warlof warlof added the complexity/high This task has a high complexity level label Oct 25, 2020
@lk77
Copy link
Author

lk77 commented Oct 26, 2020

I don't know, i plan to do the v4 update but i haven't done yet, so i don't know, if nothing has been done to correct it, it don't think it's gone.

i need to change the user, because it's better to run some commands as www-data than as root, because it could cause issues with file permissions since the webserver run with www-data. On multiple occasions, doing artisan commands as root has led to rooted logs, which cannot be overriden by webserver.

@Crypta-Eve
Copy link
Member

Regardless of populating the .env file directly in the docker container.. I think that this is more a result of a misuse of su. The method you are using to change to the www-data user is using su -, where the - is indicating to give a login like change where the environment variables set would be as if you logged in directly as www-data. Doing this you lose all of the setup done by docker. Quote from the man page:

   -, -l, --login
      Start the shell as a login shell with an environment similar to a real login:
      •   clears all the environment variables except TERM and variables specified by --whitelist-environment
      •   initializes the environment variables HOME, SHELL, USER, and PATH
      •   changes to the target user’s home directory
      •   sets argv[0] of the shell to '-' in order to make the shell a login shell

Instead of using su - www-data you should try using either su www-data or if the env still does not persist, su -m www-data. In this command the -m flag tells us to preserve the environment.

Either way, can you confirm if this issue is ongoing for you in the seat 4 image?

@lk77
Copy link
Author

lk77 commented Jul 27, 2021

thanks, i will try with your command, i will keep you updated.

@Crypta-Eve
Copy link
Member

How did you get on with this? Are you still encountering issues?

@lk77
Copy link
Author

lk77 commented Oct 18, 2021

Hello,

sorry for not replying,
the command was working fine, the env was kept.

now i'm using docker-compose exec -u www-data seat-web bash it way easier

@lk77 lk77 closed this as completed Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity/high This task has a high complexity level docker Things related to docker
Projects
None yet
Development

No branches or pull requests

3 participants