Docker-compose fpm basic setup fails

I’m trying to install Nextcloud on an existing webserver. My docker-compose.yml file is as follows:

version: '2'


services:
  db:
    image: mariadb:10.5
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - /home/webservers/nextcloud_vols/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=pass
      - MYSQL_PASSWORD=pass
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: nextcloud:fpm
    restart: always
    links:
      - db
    ports:
      - "9000:9000"    # This was added later to test the container without nginx
    volumes:
      - /home/webservers/nextcloud_vols/nextcloud:/var/www/html
    environment:
      - MYSQL_PASSWORD=pass
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db

I have another container running nginx, and the config is:

upstream nextcloud_container {
    server app:9000;
}

server {
    listen 80;
    server_name cloudstorage.mydomain.com;
    client_body_buffer_size 10M;
    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name cloudstorage.mydomain.com;
    ssl_certificate /etc/letsencrypt/live/cloudstorage.mydomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cloudstorage.mydomain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    location / {
        proxy_pass http://nextcloud_container; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header x-forwarded-proto https;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_read_timeout 3600;
    }

}

I’ve also installed the Letsencrypt certificates for https. Accessing my domain gives a 502 Bad Gateway. nginx logs:

2022/10/06 15:55:09 [error] 10#10: *381 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 157.40.112.194, server: cloudstorage.mydomain.com, request: "GET / HTTP/1.1", upstream: "http://172.19.0.12:9000/", host: "cloudstorage.mydomain.com"
157.40.112.194 - - [06/Oct/2022:15:55:09 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
2022/10/06 15:55:10 [error] 10#10: *381 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: xx.xx.xx.xx, server: cloudstorage.mydomain.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.19.0.12:9000/favicon.ico", host: "cloudstorage.mydomain.com", referrer: "https://cloudstorage.mydomain.com/"

I exposed port 9000 on my server, and tried accessing the site through http://my_ip:9000, but I get this:

The port is open in the firewall, so that’s not the issue.
The nextcloud container logs show:

Initializing nextcloud 24.0.5.1 ...
New nextcloud instance
Initializing finished
[06-Oct-2022 15:34:15] NOTICE: fpm is running, pid 1
[06-Oct-2022 15:34:15] NOTICE: ready to handle connections

Similarly the db container logs:

2022-10-06 15:34:06+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.5.17+maria~ubu2004 started.
2022-10-06 15:34:07+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-10-06 15:34:07+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.5.17+maria~ubu2004 started.
2022-10-06 15:34:07+00:00 [Note] [Entrypoint]: Initializing database files


PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following command:

'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at https://mariadb.com/kb

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.

Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

2022-10-06 15:34:08+00:00 [Note] [Entrypoint]: Database files initialized
2022-10-06 15:34:08+00:00 [Note] [Entrypoint]: Starting temporary server
2022-10-06 15:34:08+00:00 [Note] [Entrypoint]: Waiting for server startup
2022-10-06 15:34:08 0 [Note] mysqld (mysqld 10.5.17-MariaDB-1:10.5.17+maria~ubu2004) starting as process 89 ...
2022-10-06 15:34:08 0 [Warning] You need to use --log-bin to make --binlog-format work.
2022-10-06 15:34:08 0 [Note] InnoDB: Uses event mutexes
2022-10-06 15:34:08 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-10-06 15:34:08 0 [Note] InnoDB: Number of pools: 1
2022-10-06 15:34:08 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
2022-10-06 15:34:08 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2022-10-06 15:34:08 0 [Note] InnoDB: Using Linux native AIO
2022-10-06 15:34:08 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
2022-10-06 15:34:08 0 [Note] InnoDB: Completed initialization of buffer pool
2022-10-06 15:34:08 0 [Note] InnoDB: 128 rollback segments are active.
2022-10-06 15:34:08 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-10-06 15:34:08 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-10-06 15:34:08 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-10-06 15:34:08 0 [Note] InnoDB: 10.5.17 started; log sequence number 45106; transaction id 20
2022-10-06 15:34:08 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-10-06 15:34:08 0 [Warning] 'user' entry 'root@27e9b720f400' ignored in --skip-name-resolve mode.
2022-10-06 15:34:08 0 [Warning] 'proxies_priv' entry '@% root@27e9b720f400' ignored in --skip-name-resolve mode.
2022-10-06 15:34:08 0 [Note] Reading of all Master_info entries succeeded
2022-10-06 15:34:08 0 [Note] Added new Master_info '' to hash table
2022-10-06 15:34:08 0 [Note] mysqld: ready for connections.
Version: '10.5.17-MariaDB-1:10.5.17+maria~ubu2004'  socket: '/run/mysqld/mysqld.sock'  port: 0  mariadb.org binary distribution
2022-10-06 15:34:09+00:00 [Note] [Entrypoint]: Temporary server started.
2022-10-06 15:34:13+00:00 [Note] [Entrypoint]: Creating database nextcloud
2022-10-06 15:34:13+00:00 [Note] [Entrypoint]: Creating user nextcloud
2022-10-06 15:34:13+00:00 [Note] [Entrypoint]: Giving user nextcloud access to schema nextcloud
2022-10-06 15:34:13+00:00 [Note] [Entrypoint]: Securing system users (equivalent to running mysql_secure_installation)

2022-10-06 15:34:13+00:00 [Note] [Entrypoint]: Stopping temporary server
2022-10-06 15:34:13 0 [Note] mysqld (initiated by: unknown): Normal shutdown
2022-10-06 15:34:13 0 [Note] Event Scheduler: Purging the queue. 0 events
2022-10-06 15:34:13 0 [Note] InnoDB: FTS optimize thread exiting.
2022-10-06 15:34:13 0 [Note] InnoDB: Starting shutdown...
2022-10-06 15:34:13 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2022-10-06 15:34:13 0 [Note] InnoDB: Buffer pool(s) dump completed at 221006 15:34:13
2022-10-06 15:34:13 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2022-10-06 15:34:13 0 [Note] InnoDB: Shutdown completed; log sequence number 45118; transaction id 21
2022-10-06 15:34:13 0 [Note] mysqld: Shutdown complete

2022-10-06 15:34:13+00:00 [Note] [Entrypoint]: Temporary server stopped

2022-10-06 15:34:13+00:00 [Note] [Entrypoint]: MariaDB init process done. Ready for start up.

2022-10-06 15:34:13 0 [Note] mysqld (mysqld 10.5.17-MariaDB-1:10.5.17+maria~ubu2004) starting as process 1 ...
2022-10-06 15:34:13 0 [Warning] You need to use --log-bin to make --binlog-format work.
2022-10-06 15:34:13 0 [Note] InnoDB: Uses event mutexes
2022-10-06 15:34:13 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2022-10-06 15:34:13 0 [Note] InnoDB: Number of pools: 1
2022-10-06 15:34:13 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
2022-10-06 15:34:13 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2022-10-06 15:34:13 0 [Note] InnoDB: Using Linux native AIO
2022-10-06 15:34:13 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
2022-10-06 15:34:13 0 [Note] InnoDB: Completed initialization of buffer pool
2022-10-06 15:34:13 0 [Note] InnoDB: 128 rollback segments are active.
2022-10-06 15:34:13 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2022-10-06 15:34:13 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2022-10-06 15:34:13 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2022-10-06 15:34:13 0 [Note] InnoDB: 10.5.17 started; log sequence number 45118; transaction id 20
2022-10-06 15:34:13 0 [Note] Plugin 'FEEDBACK' is disabled.
2022-10-06 15:34:13 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2022-10-06 15:34:13 0 [Note] InnoDB: Buffer pool(s) load completed at 221006 15:34:13
2022-10-06 15:34:13 0 [Note] Server socket created on IP: '::'.
2022-10-06 15:34:13 0 [Note] Reading of all Master_info entries succeeded
2022-10-06 15:34:13 0 [Note] Added new Master_info '' to hash table
2022-10-06 15:34:13 0 [Note] mysqld: ready for connections.
Version: '10.5.17-MariaDB-1:10.5.17+maria~ubu2004'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution

I feel like I’m missing something basic here, can someone guide me?
Thanks!

I think the issue is you are forwarding port 9000 on the host to port 9000 on the container which is unused. You should forward to port 80 or 443 as appropriate. Try for example “9000:80”

1 Like