Database error installing farmOS

I’m trying to install a test instance of farmOS locally.

I’ve changed the host to db
Also tried various docker-compose files I’ve found and I end up with the same result.
Starting to think it’s something on my side, rather than the install.

Latest try is with this file:

version: '3'
services:
  db:
    image: postgres:12
    volumes:
      - './db:/var/lib/postgresql/data'
    ports:
      - '5432:5432'
    environment:
      POSTGRES_USER: farm
      POSTGRES_PASSWORD: farm
      POSTGRES_DB: farm

  www:
    depends_on:
      - db
    image: farmos/farmos:2.x-dev
    volumes:
      - './www:/opt/drupal'
    ports:
      - '80:80'
    environment:
      XDEBUG_MODE: debug
      XDEBUG_CONFIG: discover_client_host=yes
    

Don’t think I’ll need the dev environment tho.

1 Like

First do;

docker pull farmos/farmos:2.x-dev
docker pull postgres:12

Then try this as your docker-compose.yml file;

version: '2'
services:
  db:
    image: postgres:12
    volumes:
      - './test-db:/var/lib/postgresql/data'
    ports:
      - '5432:5432'
    environment:
      POSTGRES_USER: farm
      POSTGRES_PASSWORD: farm
      POSTGRES_DB: farm

  www:
    depends_on:
      - db
    image: farmos/farmos:2.x-dev
    entrypoint: /bin/bash
    command:
      - -c
      - |
        set -ex

        wait_db_ready() {
            while { ! exec 3<>/dev/tcp/db/5432; } > /dev/null 2>&1; do sleep 0.1; done
        }

        if [ -d /opt/drupal ] && ! [ "$$(ls -A /opt/drupal/)" ]; then
          echo "farmOS codebase not detected. Copying from pre-built files in the Docker image."
          cp -rp /var/farmOS/. /opt/drupal

          wait_db_ready

          su www-data -s /bin/bash -c 'drush site-install farm --locale=en --db-url=pgsql://farm:farm@db/farm --site-name=Test0 --account-name=root --account-pass=test'

          mkdir -p /opt/drupal/web/sites/default/private/files
          chown -R www-data:www-data /opt/drupal/web/sites/default/private/files

          /bin/bash -c "printf \"\\\$$settings['file_private_path'] = '/opt/drupal/web/sites/default/private/files';\n\" >> /opt/drupal/web/sites/default/settings.php"
        fi

        wait_db_ready

        exec docker-entrypoint.sh apache2-foreground
    volumes:
      - './test-www:/opt/drupal'
    ports:
      - '80:80'
    environment:
      XDEBUG_MODE: 'off'

3 Likes

You can also check if database container is running docker compose ps and if it doesn’t report any errors docker compose logs db.

2 Likes

There’s also an argument for restarting your computer and the docker daemon. Sometimes networking things especially can get into weird states with docker.

1 Like

Tried your tip @Symbioquine
But no install webpage this time.

I’ll try a restart, but with your example, is this step from farmos.org not needed?

docker run --rm -p 80:80 -v "${PWD}/sites:/opt/drupal/web/sites" farmos/farmos:2.x.y
1 Like

That docker-compose.yml file should result in a fully working already installed farmOS instance. i.e. no manual install step - just login with the username ‘root’ and the password ‘test’.

Nope, those are different approaches to a similar end. If you’ve been running things like that, it’s probably best to do a docker ps and see if you’ve got any farmOS/DB instances already running…

2 Likes

@pat Are you following the directions from the “Development environment” documentation?

That is different from the “Hosting” instructions, which is focused on production hosting, and doesn’t use Docker Compose. The development environment instructions should give you a working environment simply by copying the example docker-compose.yml and running docker-compose up.

Cool

But I can’t figure out the URL for farmOS

1 Like

Try http://localhost:80 (the port 80 is the default so it is equivalent to omit it, I just put it there for clarity)

1 Like

Nah…

1 Like

Ok. Thanks.
I tried the hosting instructions, but could not find a good and clear info on setting up the database.
So I ended up with different .yml-files and all gave the same error.

The dev environment was the last try.

2 Likes

Yea that’s because there are a lot of different ways to set up a production database - so the farmOS.org instructions leave that up to you. The “Development Environment” take a very specific approach with a PostgreSQL database running in Docker.

1 Like

OK. So it’s not “normal” approach to run PostgreSQL in docker?

1 Like

farmOS (being Drupal) supports PostgreSQL, MySQL/MariaDB, SQLite3 - either in Docker or not in Docker. It’s up to the host. :slight_smile:

1 Like

@pat If you are around and want some live help setting up your local dev env, chat might be easier than forum. https://app.element.io/#/room/#farmOS:matrix.org

1 Like

I’ll try that after som more testing with the tips I’ve got so far first.

1 Like

Have you found any solution? I had the same error, I tried to fix it and now I get it:


It’s work pretty good, thank Symbioquine and pat for open topic!
Have a nice weekend!
:slightly_smiling_face:

3 Likes

I’m not give up :cowboy_hat_face:
p/s: on Ubuntu instead of desktop

1 Like

@tamtran Can we start a new forum topic for your new issue? It’s not a “database error” anymore. We could also debug in chat if that’s easier (I see you’ve posted in chat this morning, so I’ll check in there too)… :slight_smile: