I’m having trouble hosting FarmOS in a docker container. The examples I can find use a volume for the sites directory
If I do that I get an error on installation, because my sites directory is empty.
Should I be pre-populating the sites directory before starting the container, or is there a different workaround that I’m missing?
@gmagnusson Are you using the official farmOS image? And if so, are you using 1.x or 2.x? And is it the production image or the development image?
We have a special
docker-entrypoint.sh script that helps to populate the
sites directory for you the first time. This works a bit differently in 1.x vs 2.x and prod vs dev images. Happy to point you to the relevant code to help you understand.
If you are overriding the image (or especially the entrypoint script), then it might be breaking this logic.
Here is the 2.x entrypoint script: farmOS/docker-entrypoint.sh at 2.x · farmOS/farmOS · GitHub
Notice this line:
# If the sites directory is empty, populate it from pre-built files.
if [ -d /opt/drupal/web/sites ] && ! [ "$(ls -A /opt/drupal/web/sites/)" ]; then
echo "farmOS sites directory not detected. Copying from pre-built files in the Docker image."
cp -rp /var/farmOS/web/sites/. /opt/drupal/web/sites
This is just helper logic to fix the exact issue you’re describing. Alternatively, if you don’t want to use this logic, you can simply install farmOS using a standard Drupal process, which would be to manually copy
settings.php and make it writable by
Thank you, that clarifies some things.
Here is the full docker-compose.yml
I can see that sites is populated with some content, but
/sites/default/settings.php is not in there
After I run
docker-compose up this is what I find in sites:
│ ├── default.services.yml
│ ├── default.settings.php
│ └── files
Ah OK then it may be a permissions issue… During installation, Drupal will attempt to copy
settings.php itself and then write database details etc to it. But if that directory is not writeable by
www-data then it won’t be able to. This would not only affect initial installation, but also uploading files later when you’re using farmOS.
Can you check whether or not that directory is writable by
Oh wait I’m also noticing some inconsistencies in your
docker-compose.yml (unrelated to this issue perhaps, but worth asking about)… it looks like you’ve got a mix of farmOS 1.x vs 2.x and development vs production templates…
PostgreSQL is the recommended database for farmOS 2.x (MariaDB will also work, but I assume you go that from the 1.x
Also, I see
XDEBUG_CONFIG environment variable being used. This will only have an affect if you are running the
2.x-dev images, so it’s harmless… but it also looks like you copied that from the 1.x template. Those variables are different in 2.x.
Development: farmOS/docker-compose.development.yml at 7.x-1.x · farmOS/farmOS · GitHub
Production: farmOS/docker-compose.production.yml at 7.x-1.x · farmOS/farmOS · GitHub
Development: farmOS/docker-compose.development.yml at 2.x · farmOS/farmOS · GitHub
Production: farmOS/docker-compose.production.yml at 2.x · farmOS/farmOS · GitHub
@gmagnusson Did you figure this out? Was it a permissions issue?
What operating system are you running Docker on?
@raheel seems to be having a similar (but different) issue, which may also be permissions related: Apache/2.4.38 (Debian) Server at localhost Port 80
I’m wondering if maybe both of you are running on Windows? I’m not very familiar with how Linux permissions (which is what is expected within the Docker container) are treated by a Windows host system.
I encountered this issue when i used the production.yml file and when i used the development.yml i encounter the other issue i have opened up after the modules started to get installed.
@mstenta I did get past this issue but the solution is unconfirmed.
I reverted back to the recommended
docker-compose.development.yml for 2.x. I still saw this error on multiple attempts to install and fiddle with permissions. Eventually I got past it simply by refreshing the page. Seems like
settings.php was not copied until I rendered the install page a second time.
I was running this on MacOS.
The other error I mentioned here The website encountered an unexpected error. Please try again later - #2 by gmagnusson was running on AWS Fargate
Did you faced this issue?
i am trying to connect to a postgres DB i made on my local machine i am trying to connect to that but its giving me that error, if you faced it how did you overcame it? Do i have to enable the local host and port in firewall, or through some settings in postgresql?
I saw something similar. I was launching both FarmOS and Postgres from docker-compose. Initially I set the DB host as
localhost and got this error. When I set the host to
db which is the service name in docker-compose it worked fine.
If you’re running Postgres outside of docker, maybe there is some trick required to make sure the docker network has access to it. I don’t know exactly what steps you might need.