GithubHelp home page GithubHelp logo

rcdailey / nextcloud-cronjob Goto Github PK

View Code? Open in Web Editor NEW
68.0 7.0 17.0 37 KB

A simple container to run cron.php in your Nextcloud docker container

Home Page: https://hub.docker.com/r/rcdailey/nextcloud-cronjob/

Dockerfile 9.83% Shell 90.17%

nextcloud-cronjob's Introduction

Nextcloud Cron Job Docker Container

Simple cronjob support for your Nextcloud Docker container!

Actions Status

Summary

This container is designed to run along side your Nextcloud container to execute its /var/www/html/cron.php at a regular interval. There is an "official" way of doing this, however it doesn't work when you run your Nextcloud container using a non-root user. I also personally feel that this solution is easier to manage, since it doesn't require the same environment as Nextcloud itself (i.e. no network requirements, no database requirements, etc).

Setup Instructions

Since Nextcloud's entire setup can get rather complex with Docker, I highly recommend you set up everything using Docker Compose.

Below is an example of how you set up your docker-compose.yml to work with Nextcloud using this container. Note that the app service is greatly simplified for example purposes. It is only to show usage of the cronjob image in conjunction with your Nextcloud container. Note for this example, the docker-compose.yml file is located at ~/docker_services/nextcloud/docker-compose.yml.

version: '3.7'

services:
  app:
    image: nextcloud:apache

  cron:
    image: rcdailey/nextcloud-cronjob
    restart: always
    network_mode: none
    depends_on:
    - app
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro
    - /etc/localtime:/etc/localtime:ro
    environment:
    - NEXTCLOUD_CONTAINER_NAME=app
    - NEXTCLOUD_PROJECT_NAME=nextcloud

In this example, the cron service runs with a dependency on app (which is Nextcloud itself). Every 15 minutes (default) the cron service will execute php -f /var/www/html/cron.php via the docker exec command. The NEXTCLOUD_CONTAINER_NAME and NEXTCLOUD_PROJECT_NAME work together to help identify the right container to execute the command in. In this case, my project name is nextcloud because Docker Compose uses the name of the directory containing the docker-compose.yml file to prefix the name of the image. And container name is app because that's what I named the service in the YAML file.

Note that if you don't use Docker Compose, you can leave NEXTCLOUD_PROJECT_NAME blank or omitted entirely. Please see the Environment Variables section below for more details on configuration and how this all works.

Troubleshooting

Errors you may encounter are below with proposed solutions.

  • ERROR: Shell "bash" does not exist in the Nextcloud container

    The bash shell is not supported in your Nextcloud container. Easiest solution is to switch it to sh by adding this line to your environment: section of your docker-compose.yml:

    - NEXTCLOUD_EXEC_SHELL=sh
  • OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: "bash": executable file not found in $PATH": unknown

    Older versions of the nextcloud-cronjob container were hard-coded to use bash as the shell program executed inside your Nextcloud container. However, some Nextcloud containers do not have bash. Please update to the latest version of rcdailey/nextcloud-cronjob and follow the steps provided in the previous bullet point.

Environment Variables

  • NEXTCLOUD_CONTAINER_NAME
    Required. This is the name of the running Nextcloud container (or the service, if NEXTCLOUD_PROJECT_NAME is specified).

  • NEXTCLOUD_PROJECT_NAME
    The name of the project if you're using Docker Compose. The name of the project, by default, is the name of the context directory you ran your docker-compose.yml from. This helps to build a "hint" used to identify the Nextcloud container by name. The hint is built as:

    ${NEXTCLOUD_PROJECT_NAME}_${NEXTCLOUD_CONTAINER_NAME}
  • NEXTCLOUD_CRON_MINUTE_INTERVAL
    The interval, in minutes, of how often the cron task executes. The default is 15 minutes.

  • NEXTCLOUD_EXEC_USER
    The user that should be used to run the cron tasks inside the Nextcloud container. This parameter is specified to the docker exec command from this container. By default, the user used is www-data, which is also the default user used inside Nextcloud, unless you've overridden it. You may also define this environment variable to be blank (e.g. NEXTCLOUD_EXEC_USER=) which results in the tasks being executed using the Nextcloud container's running user. Specifically, the --user option will not be provided to the docker exec command.

  • NEXTCLOUD_EXEC_SHELL
    Allows specifying a custom shell program that will be used to execute cron tasks inside the Nextcloud container. This shell program must exist inside the Nextcloud container itself (validation happens on start up to ensure this). The default value if not specified is bash.

  • NEXTCLOUD_EXEC_SHELL_ARGS
    Allows custom arguments to be passed to the shell program specified by NEXTCLOUD_EXEC_SHELL. See the detailed documentation provided later on in this document for more information. At minimum, the arguments passed to your shell program must allow for the execution of a series of string commands. The default value if not specified is -c.

  • DEBUG
    Enables more verbose logging in core scripts. Useful only for development. To get more verbose output in your own custom cron scripts, use set -x in the actual script.

Container Health

If you do docker-compose ps, you will see the active health of the container. The following logic is checked every interval of the health check. If any of these checks fail, it is likely the container's health status will become unhealthy. In this case, you should restart the container.

  1. The crond process must be running.
  2. The Nextcloud container must be available and running.

Because the Nextcloud container can be restarted while the the cronjob container is running, its container ID is not cached. Each time the cron task executes, it searches for the ID of the container. This ensures that even if you restart the Nextcloud container, the cronjob container will always function.

Customizing Cron Tasks

This container provides the ability for you to run additional tasks inside the Nextcloud container in addition to the default cron.php task. To add your custom tasks, follow these steps:

  1. Write a shell script that runs the commands that will be part of your task. This shell script must have the .sh extension. An example of the contents of such a script is below. As an optional security measure, do not make this shell script executable. The contents of the file are piped into sh, so the executable bit and shebang line are not used or required.

    php -f /var/www/html/cron.php
  2. Mount this shell script inside the /cron-scripts directory. Here's an example if you're using docker-compose.yml:

    services:
      cron:
        image: rcdailey/nextcloud-cronjob
        volumes:
        - ./my-scripts/do-something.sh:/cron-scripts/do-something.sh:ro
  3. Recreate the container. Your script will now execute in the Nextcloud container at a regular interval.

Multiple scripts are supported. The container will search for all *.sh files inside the /cron-scripts directory inside the container. To make supporting multiple scripts easier, you can also map a directory on the host to the /cron-scripts directory in the container:

services:
  cron:
    image: rcdailey/nextcloud-cronjob
    volumes:
    - ./my-scripts:/cron-scripts:ro

As an optional safety measure, mount the directory or files as read-only (via the :ro at the end). The container should not modify the files, but it doesn't hurt to be explicitly strict.

Customizing the Shell

By default, all cron task scripts in the /cron-scripts directory are executed with bash. However, not all Nextcloud containers have bash. In this case, you may want to override it with a shell like sh. You can accomplish this (as well as customizing the arguments passed to the shell) with NEXTCLOUD_EXEC_SHELL and NEXTCLOUD_EXEC_SHELL_ARGS.

The shell args are used when passing the contents of script files to the shell executable inside the Nextcloud container. Customizing the args might be necessary depending on the shell program you choose, or you may want to leverage options for debugging purposes (See "Debugging" section for examples).

NOTE
The arguments that are passed to the shell program must, at least, allow the execution of a string of commands. See the documentation on your chosen shell for which arguments these should be.

Here is an example of how you would override bash for sh using docker-compose.yml (again, greatly simplified for example purposes; this is not a complete YAML):

services:
  cron:
    image: rcdailey/nextcloud-cronjob
    environment:
    - NEXTCLOUD_EXEC_SHELL=sh
    - NEXTCLOUD_EXEC_SHELL_ARGS=-c

Note that -c is the default for NEXTCLOUD_EXEC_SHELL_ARGS, so it isn't necessary to specify it above. However, it is explicitly specified for example purposes.

Notes

  • All cron task shell scripts run at the same interval defined by NEXTCLOUD_CRON_MINUTE_INTERVAL.
  • Modification of your own shell scripts on the host do not require that you restart/recreate the container (only when volume mappings change in the YAML file).
  • If a custom script in the /cron-scripts directory fails, it will not impede the processing of other scripts in the directory.

Debugging

All logs from crond are configured to print to stdout, so you can monitor container logs (via docker-compose logs -f). This should allow you to make sure your cron job is working. You can also use the "Overview" page in Nextcloud Settings to see if the cron job is being run regularly. Here is an example of the logs you will see:

Started crond
-------------------------------------------------------------
 Executing Cron Tasks: Thu Dec  6 17:28:00 CST 2018
-------------------------------------------------------------
> Running Script: occ-preview-pre-generate.sh
> Running Script: run_cron_php.sh
> Done

You can leverage NEXTCLOUD_EXEC_SHELL_ARGS to get more verbose output from your scripts. For example, for bash you can specify -x for debug mode. So you could use this in your YAML:

services:
  cron:
    image: rcdailey/nextcloud-cronjob
    environment:
    - NEXTCLOUD_EXEC_SHELL_ARGS=-xc

Note the addition of -x in the arguments. This will provide line-by-line output for each cron task shell script executed.

nextcloud-cronjob's People

Contributors

clewsy avatar rcdailey avatar skjnldsv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nextcloud-cronjob's Issues

crond not starting

Hey :)
First of all thank you for creating this Docker image. I was looking for something like this for ever!
I just have the issue that crond is not starting. see log:

Will search for Nexcloud container as a Docker Compose service
Project: nextcloud, Service: app
Found Nextcloud container with ID 623030c27720
Chosen shell "bash" was found in the Nextcloud container
Starting crond

after that the log file ends.

How can i fix this?

Support for Alpine based Nextcloud images

I tried to setup nextcloud-cronjob with nextcloud:19-fpm-alpine image and got this error:

OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: "bash": executable file not found in $PATH": unknown

I think this is because Alpine OS uses sh instead of bash. It would be great to have this supported.

Work around for customized cron jobs using custom intervals

Hi @bondif!

I was searching a way to execute the custom script twice a day (#16) and tested a successful way to do it.
It probably can be optimized, however it worked for me, and I'm using it in my Nextcloud home installation.

I have set my NEXTCLOUD_CRON_MINUTE_INTERVAL=5, in this way I could manage to always have round minutes.
Then I have created the desired script inside the "cron-scripts" folder:

#!/bin/sh
DesiredHourMinute=`date +%H:%M` #Hour and minute are getting stored into this variable
if [[ $DesiredHourMinute == "04:00" ]] || [[ $DesiredHourMinute == "16:00" ]]; then
	php occ files:scan --all # Scan all files at the desired hour above
fi

My containers are using UTC, I don't know if there's a way to set them to the local time, but I kept this in mind when I have chosen the time when the scripts should run.

Using this script I achieve the desired full scan twice a day and also it's also registered into the conteiner log:

Container Name: nextcloud-app
Found Nextcloud container with ID 26e0a3ffa81e
Chosen shell "bash" was found in the Nextcloud container
Starting crond
-------------------------------------------------------------
 Executing Cron Tasks: Thu Nov 17 22:15:00 UTC 2022
-------------------------------------------------------------
> Nextcloud Container ID: 26e0a3ffa81e
> Running Script: ./run-cron-php.sh
> Running Script: ./Scan-All-Files.sh
Starting scan for user 1 out of 2 (DMTwo)
Starting scan for user 2 out of 2 (User2)
-------------------------------------------------------------
 Executing Cron Tasks: Thu Nov 17 22:20:00 UTC 2022
-------------------------------------------------------------
> Nextcloud Container ID: 26e0a3ffa81e
> Running Script: ./run-cron-php.sh
> Running Script: ./Scan-All-Files.sh
> Done
-------------------------------------------------------------
 Executing Cron Tasks: Thu Nov 17 22:25:00 UTC 2022
-------------------------------------------------------------
> Nextcloud Container ID: 26e0a3ffa81e
> Running Script: ./run-cron-php.sh
> Running Script: ./Scan-All-Files.sh
> Done
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 9998    | 40685 | 00:10:23     |
+---------+-------+--------------+
> Done

Hi @rcdailey,
Please if possibly add this work around into your instructions.
I think it can help others using custom scripts.

I wish the best to you both.
Thanks a lot!

ERROR: Unable to find the Nextcloud container

Hi,

Sorry to bother with what seems like such an easy fix, but I've tried everything and gone through the other issues. The solutions provided doesn't seem to rectify the problem for me.

I am getting the following error described above in the cronjob logs.

Will search for Nexcloud container as a Docker Compose service
Project: nextcloud, Service: nextcloud
ERROR: Unable to find the Nextcloud container

Below is my config for Nextcloud in docker-compose.yml file:

nextcloud:
  <<: *common-keys-apps
  image: nextcloud:stable
  container_name: nextcloud
  hostname: nextcloud
  #ports:
  #  - 3000:80
  # Persistent volumes with bind mounts to easily move/backup data
  volumes:
    - $DOCKERDIR/appdata/nextcloud/html:/var/www/html
    - $DOCKERDIR/appdata/nextcloud/apps:/var/www/html/custom_apps
    - $DOCKERDIR/appdata/nextcloud/config:/var/www/html/config
    - $DOCKERDIR/appdata/nextcloud/data:/var/www/html/data
  # Environment (internal to the container) variables to simplify setup
  environment:
    # Redis host name (container_name)
    - REDIS_HOST=$NEXTCLOUD_REDIS__HOST
    - NEXTCLOUD_TRUSTED_DOMAIN=files.$DOMAINNAME_CLOUD_SERVER
    - TRUSTED_PROXIES=192.168.90.254/24
  labels:
    - "traefik.enable=true"
    ## HTTP Routers
    - "traefik.http.routers.nextcloud-rtr.entrypoints=https"
    - "traefik.http.routers.nextcloud-rtr.rule=Host(`files.$DOMAINNAME_CLOUD_SERVER`)"
    - "traefik.http.routers.nextcloud-rtr.tls=true"
    - “traefik.http.routers.nextcloud-rtr.middlewares=cloud,cloud-dav”
    ## Middlewares
    - "traefik.http.routers.nextcloud-rtr.middlewares=chain-nextcloud@file"
    ## HTTP Services
    - "traefik.http.routers.nextcloud-rtr.service=nextcloud-svc"
    - "traefik.http.services.nextcloud-svc.loadbalancer.server.port=80"

And for cron-job config in the same file:

cron:
  # <<: *common-keys-core
  image: rcdailey/nextcloud-cronjob
  restart: always
  network_mode: none
  depends_on:
    - nextcloud
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock:ro
    - /etc/localtime:/etc/localtime:ro
  environment:
    - NEXTCLOUD_CONTAINER_NAME=nextcloud
    - NEXTCLOUD_PROJECT_NAME=nextcloud
    - NEXTCLOUD_CRON_MINUTE_INTERVAL=5
    #- DEBUG

Thank you for your time.

Could not open input file: /var/www/html/cron.php

Hello!

I have just started using your unRAID app with the official Nextcloud docker container, and for some reason I am getting this error when it tries to run the script. The cron.php file does exist inside that folder and is properly mapped too.

-------------------------------------------------------------
 Executing Cron Tasks: Wed Feb 28 13:35:00 UTC 2024
-------------------------------------------------------------
> Nextcloud Container ID: 3cbcdb301c80
> Running Script: ./run-cron-php.sh
Could not open input file: /var/www/html/cron.php
> Done

Initially I was getting

-------------------------------------------------------------
 Executing Cron Tasks: Wed Feb 28 13:25:00 UTC 2024
-------------------------------------------------------------
> Nextcloud Container ID: 3cbcdb301c80
> Running Script: ./run-cron-php.sh
Cannot write into "config" directory!
This can usually be fixed by giving the web server write access to the config directory.

But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.
See https://docs.nextcloud.com/server/28/go.php?to=admin-config
> Done

But I solved it by giving rw perms to www-data.

I don't really understand why it cant execute it now. I've now gone as far as giving rwx perms to owner, group, and other.

since compose v2, the container naming rule has changed.

refer to docker/compose#8655 , the rule has changed <project-name>_<service-name>_<replica-number> to <project-name>-<service-name>-<replica-number>

I tried to change this line

containerName="${NEXTCLOUD_PROJECT_NAME}_"

to

containerName="${NEXTCLOUD_PROJECT_NAME}-"

it seems works fine.

 ⠿ Container nextcloud-nextapp-1  Running                                                                                                  0.0s
 ⠿ Container nextcloud-cron-1     Created                                                                                                  0.1s
Attaching to nextcloud-cron-1
nextcloud-cron-1  | Will search for Nexcloud container as a Docker Compose service
nextcloud-cron-1  | Project: nextcloud, Service: nextapp
nextcloud-cron-1  | Found Nextcloud container with ID 396cdc5c652e
nextcloud-cron-1  | Chosen shell "sh" was found in the Nextcloud container
nextcloud-cron-1  | Starting crond
nextcloud-cron-1  | -------------------------------------------------------------
nextcloud-cron-1  |  Executing Cron Tasks: Thu Dec 16 17:00:00 HKT 2021
nextcloud-cron-1  | -------------------------------------------------------------
nextcloud-cron-1  | > Nextcloud Container ID: 396cdc5c652e
nextcloud-cron-1  | > Running Script: ./run-cron-php.sh
nextcloud-cron-1  | > Done

maybe to complex ...so it costs live time

Will search for Nexcloud container as a Docker Compose service

Project: nextcloud, Service: nextcloud-app

ERROR: Unable to find the Nextcloud container

Will search for Nexcloud container as a Docker Compose service

Project: nextcloud, Service: nextcloud-app

ERROR: Unable to find the Nextcloud container

ERROR: Shell "bash" does not exist in the Nextcloud container

  • I'm using docker swarm.
  • It was working before
  • If I manually exec bash with the container ID, it works

Issue:

There seems to be an issue with the grep.
We can have multiple instances on the same node, we still need to pick only one.
See logs bellow, the nextcloud_exec_no_shell command is executed with two ID: 9e19821d2d60 552ed77d1b59

Logs:

nextcloud_cron.1.z4e0bdszbg6h@srv2    | + source /nextcloud-exec.sh
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + [[ -z nextcloud_app.* ]]
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + [[ -n '' ]]
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + echo 'Container Name: nextcloud_app.*'
nextcloud_cron.1.z4e0bdszbg6h@srv2    | Container Name: nextcloud_app.*
nextcloud_cron.1.z4e0bdszbg6h@srv2    | ++ /find-container.sh
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + containerId='9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2    | 552ed77d1b59'
nextcloud_cron.1.z4e0bdszbg6h@srv2    | Found Nextcloud container with ID 9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2    | 552ed77d1b59
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + [[ -z 9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2    | 552ed77d1b59 ]]
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + echo 'Found Nextcloud container with ID 9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2    | 552ed77d1b59'
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + nextcloud_exec_no_shell '9e19821d2d60
nextcloud_cron.1.z4e0bdszbg6h@srv2    | 552ed77d1b59' sh -c 'command -v "bash"'
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + echo 'ERROR: Shell "bash" does not exist in the Nextcloud container'
nextcloud_cron.1.z4e0bdszbg6h@srv2    | + exit 1
nextcloud_cron.1.z4e0bdszbg6h@srv2    | ERROR: Shell "bash" does not exist in the Nextcloud container

Cron is not running

When starting the docker container it’s starting properly and everything loads properly, even setting up crontab, so entry point.sh is doing everything right, but it doesn’t run cron-tasks.sh if I run it manually it runs the Cron successfully

Custom interval for customized cron jobs

Hi,

I'm using a customized cron task to run php occ files:scan --all, and since this takes much more time, it doesn't make sense to run it in the same interval as the cron.php file.
Is there a way to have custom intervals for each cron job?

Thank you

php command not found

Hello,

I've downloaded and installed your docker app from the app in Unraid and I think it's cool, so thank you for that.

I was just wondering if you know why I'm having a php: command not found in the console logs and also when I try to run php in the cli?

image

Thank you for your input.

Support for ARM

At the moment, it seems like the ARM architecture is not supported by the image currently on Docker Hub. It would be great if support could be added, for I would like to use it on my Raspberry Pi.

Cannot Write Into "config" directory

Hello,

I'm using Unraid and grabbed your Docker from the Community App Store.

When running, I see the following in my logs:

 Executing Cron Tasks: Fri Mar  8 21:15:00 UTC 2024
-------------------------------------------------------------
> Nextcloud Container ID: 1259567c48db
> Running Script: ./run-cron-php.sh
Cannot write into "config" directory!
This can usually be fixed by giving the web server write access to the config directory.

But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.
See https://docs.nextcloud.com/server/28/go.php?to=admin-config
> Done

Any advice? I've tried to add the cron docker to the Nextcloud PHP config as follows:

  'trusted_proxies' => 
  array (
    0 => 'NginxProxyManagerOfficial',
    1 => 'Nextcloud-cronjob',
  ),

This is the error log directly from nextcloud:
image

I just cant seem to figure it out. Thank you!!

Unable to find container when used in Swarm stack

The nextcloud-cronjob container is working great for my docker-compose setup with the following configuration:

  nextcloud-cron:
    image: rcdailey/nextcloud-cronjob
    container_name: nextcloud-cron
    restart: unless-stopped
    network_mode: none
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /etc/localtime:/etc/localtime:ro
      - ${CRONSCRIPTS}:/cron-scripts:ro
    environment:
      - NEXTCLOUD_CONTAINER_NAME=nextcloud-app
    depends_on:
      - nextcloud-app

I am now migrating to a swarm service, but it doesn't appear I can use this same cron solution. My understanding is that the swarm naming scheme, due to replicas and unique service names, is not compatible. Example:

As single docker-compose file:

user@docker:$ docker ps --format '{{.Names}},{{.ID}}'
nextcloud-app,84195755d4f2
nextcloud-db,9f027708cd03
nextcloud-redis,7c491729a707

Converted to swarm stack named "nextcloud":

user@docker:$ docker ps --format '{{.Names}},{{.ID}}'
nextcloud_nextcloud-app.1.na20bhtl91z98j8lr5hjjgq69,a61e78034e9d
nextcloud_nextcloud-db.1.tuysjjdnuzetk84y4jmcejeco,86fa6784f9e7
nextcloud_nextcloud-redis.1.yn4h476s5jgp2asjqmb8ezhrp,f12b9876b2c3

Is it possible to get the swarm container names and use them with your cron container? I think your container is the best cron solution for nextcloud. Using official nextcloud:22-apache base image.

Azure webapp for containers

Here my Yaml

version: '3.8'
services:
db:
image: mysql:5.7.31
command: mysqld --sql-mode=NO_AUTO_VALUE_ON_ZERO
environment:
- MYSQL_ROOT_PASSWORD=xxxx
- MYSQL_PASSWORD=xxxx
- MYSQL_DATABASE=xxxxxxx
- MYSQL_USER=xxxxxxxxx
volumes:
- ${WEBAPP_STORAGE_HOME}/mysql:/var/lib/mysql
restart: always
app:
image: nextcloud:18.0.9
ports:
- 80:80
environment:
- MYSQL_DATABASE=xxxxxxxx
- MYSQL_USER=xxxxxxx
- MYSQL_PASSWORD=xxxxxx
- MYSQL_HOST=db
- NEXTCLOUD_TRUSTED_DOMAINS=mydomain.net
- NEXTCLOUD_DATA_DIR=/var/www/html/data/NextCloudData
restart: always
volumes:
- CloudData:/var/www/html/data/NextCloudData
- ${WEBAPP_STORAGE_HOME}/nextcloud/config:/var/www/html/config
- ${WEBAPP_STORAGE_HOME}/nextcloud/apps:/var/www/html/custom_apps
cron:
image: rcdailey/nextcloud-cronjob
restart: always
network_mode: none
depends_on:
- app
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /etc/localtime:/etc/localtime:ro
environment:
- NEXTCLOUD_EXEC_SHELL_ARGS=-xc
- NEXTCLOUD_CONTAINER_NAME=app
- NEXTCLOUD_EXEC_SHELL=sh

I get

Container logs from xxxxxx_cron_0_3e7a4656 = 2020-10-07T20:19:27.777456415Z Container Name: app Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? ERROR: Unable to find the Nextcloud container Container Name: app

ERROR: Unable to find the Nextcloud container - due to tolower()

tldr: Pay attention to uppercase letters in your project folder name.

I think this is something to either program around or at least document in your (rather nice) documentation.

It seems that docker (or docker compose) removes all case from the folder name (project name). Since my folder had a couple capital letters, and that is how I typed it into the environment variable, your cron service couldn't find it.

Once I understood, it was fairly simple to rename:
NEXTCLOUD_PROJECT_NAME=all_lower_case

While troubleshooting this I initially thought that there was an issue because of the way compose numbers the container names (nextcloud_nextcloud_1) but you seem to have figured out how to work around that.

Thanks,

Can't find docker container

I am trying to get this running but getting into the error that it can't find the docker container.

docker ps

cb2c6a9f3af2        nextcloud:latest          "/entrypoint.sh apac…"   8 days ago          Up 8 days           0.0.0.0:8080->80/tcp                             NextCloud

docker ps --format '{{.Names}},{{.ID}}' | egrep "NextCloud," | awk '{split($0,a,","); print a[2]}'

cb2c6a9f3af2

Result in portainer:

Container Name: NextCloud,
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?,
ERROR: Unable to find the Nextcloud container,

Maybe add debug information on this line when debub is enabled?

containerName="${containerName}${NEXTCLOUD_CONTAINER_NAME}"

unable to find the nextcloud container

Hey, first of all thanks for that container, but i have a problem that i cant figure out.

I have used a compose file, with the right container name and the basedir (project) name, i also tried setting the project name in an .env file, it is always the same.

i hope this is not bcs you use nextcloud:apache image...

I also tried switching from compose file version 3 to 3.7
The Debug env variable doesn't seem to do sth in this case.

here is the part of the compose:

  nextcloud:
    depends_on:
      - mariadb
      - redis
      - watchtower
      - av
    image: nextcloud:19
    container_name: nextcloud
    links:
      - av
    labels:
      - "traefik.enable=true"
      - "traefik.http.middlewares.nextcloud-caldav.redirectregex.permanent=true"
      - "traefik.http.middlewares.nextcloud-caldav.redirectregex.regex=^https://(.*)/.well-known/(card|c$
      - "traefik.http.middlewares.nextcloud-caldav.redirectregex.replacement=https://$${1}/remote.php/da$
      - "traefik.http.middlewares.nextcloud-https.redirectscheme.scheme=https"
      - "traefik.http.routers.nextcloud-http.entrypoints=http"
      - "traefik.http.routers.nextcloud-http.rule=Host(`cloud.my.domain`)"
      - "traefik.http.routers.nextcloud-http.middlewares=nextcloud-https@docker"
      - "traefik.http.routers.nextcloud.entrypoints=https"
      - "traefik.http.routers.nextcloud.rule=Host(`cloud.my.domain`)"

      # Set "Strict-Transport-Security" HTTP header for enhanced security
      - "traefik.http.middlewares.sts_headers.headers.stsSeconds=15552000"
      - "traefik.http.middlewares.sts_headers.headers.stsIncludeSubdomains=True"

      # nextcloud enable middlewares 
      - "traefik.http.routers.nextcloud.middlewares=nextcloud-caldav@docker,sts_headers"
      - "traefik.http.routers.nextcloud.tls=true"
      - "traefik.http.routers.nextcloud.tls.certresolver=le"
      - "com.centurylinklabs.watchtower.enable=true"

    networks:
      - default
    restart: 'unless-stopped'
    volumes:
      - ./data/volumes/nextcloud/html:/var/www/html

  cron:
    image: rcdailey/nextcloud-cronjob
    restart: unless-stopped
    network_mode: none
    container_name: 'cron'
    depends_on:
      - nextcloud
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /etc/localtime:/etc/localtime:ro
    environment:
      - NEXTCLOUD_CONTAINER_NAME=nextcloud
      - NEXTCLOUD_PROJECT_NAME=traefik



Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.