akaunting / docker

Docker Image for Akaunting
https://github.com/akaunting/akaunting
GNU General Public License v3.0
189 stars 88 forks source link

Akaunting container takes approximately 15 minutes before Apache is launched #65

Closed sherif-fanous closed 2 years ago

sherif-fanous commented 2 years ago

I've just started using Akaunting but came across an issue where the container would start but I'd have no access to the application for a good 15 minutes as apache wasn't starting for all that time.

I've tracked the issue to the container entrypoint file /usr/local/bin/akaunting.sh and specifically the chmod -R u=rwX,g=rX,o=rX /var/www/html command in it.

I took a copy of this entrypoint file on to the host and made a very small change in the chmod command to make it verbose

chmod -v -R u=rwX,g=rX,o=rX /var/www/html

I then bind mounted this edited file on to /usr/local/bin/akaunting.sh in the container.

By adding the -v chmod runs in verbose mode outputting a diagnostic for every file processed like the following

mode of '/var/www/html' changed from 0777 (rwxrwxrwx) to 0755 (rwxr-xr-x)
mode of '/var/www/html/.env' retained as 0644 (rw-r--r--)
mode of '/var/www/html/manifest.json' retained as 0644 (rw-r--r--)
mode of '/var/www/html/overrides' retained as 0755 (rwxr-xr-x)
.
.
.

I waited for the 15 minutes until the chmod command finished and apache was up and running then ran the following command from the host

docker logs 244ffa1930a2 | grep -v retained

Here's the output

mode of '/var/www/html' changed from 0777 (rwxrwxrwx) to 0755 (rwxr-xr-x)

Interestingly the only time chmod had to change the permissions was for the top most directory /var/www/html' The command however has to operate on almost 20,000 files because of the -R flag!!!

Is there some reason it is setup this way? I will remove the -R for now but interested to hear what issues that might cause.

Thanks

sherif-fanous commented 2 years ago

Unfortunately the following command

chown -R www-data:root /var/www/html is just as problematic but this one actually has a lot of work to do.

Any reason why permission and ownership of the files/directories is not applied in the Dockerfile while building the image?

MohammedAl-Mahdawi commented 2 years ago

Hi,

The build time depends on your machine, we optimized the images as much as we can.

The use of chown is required for this setup to work properly.

One way to get around this is to build your image using only the root user.

Thank you!

gromain commented 2 years ago

Seeing the same issue here with the slow start of the Akaunting container. Takes about 10 seconds here on a beefy 4 cores machine running at 3GHz. So yeah, a pain definitely.

I believe there are ways during the image build to define ownership of copied files and folders, or you could just do the chown step within the RUN step that get the Akaunting files.

@MohammedAl-Mahdawi do you think you could into ways of fixing this issue with an image rebuild? I feel the ownership issue would also close several other issues that users have been witnessing. At least, the chown steps should only be necessary during the setup stage (when running with AKAUNTING_SETUP). It's not necessary they run on every single start of the container.