Category: Docker

  • Playing in container

    So there are lots of times you need to work inside a docker container. Being able to do so is a simple but important skill. Easily achieved as below:-

    #If your not sure, locate the name of the docker container you want to play in
    
    docker ps
    
    #Then, jump into a bash terminal
    docker exec -it container-name bash
    

    The ‘-it’ is the switch/option for interactive terminal . Without it, it will start a bash terminal, but you wont see anything and wont be able to ‘interact’ with it!

  • OCC maintenance

    So, Nextcloud works pretty good as just a simple server instance rather than AIO (Premade collection of containers), but there comes a time when some maintenance is required.

    On the default install, there are no background maintenance running through cron. We can add some.

    Photo and file previews

    Generating all the previews for a large photo collection takes many hours. Its not something that you want to be “on demand”.

    There is a nextcloud app that can be installed which allows you to schedule/perform the preview generation. Aptly named Preview Generator, it can be found in the list of installable apps.

    Details on use can be found in :-

    Quick summary of some useful options

    # Get logged into your nextcloud container.
    docker exec -itu www-data nextcloud-container-name bash
    
    # Pre-generate the previews of photos and files
    # This is used to generate ALL previews on recent install/reinstall
    
    ./occ preview:generate-all [-vvv] [--workers=WORKERS] [--path=PATH] [user_id]

    The ‘vvv’ option switch is for verbose mode on the command line. Clearly not needed for a headless offering

    ‘workers’ is for number of concurrent operations

    “path” allows specific group of files/folders to be operated on. Using “path” overrides the “user_id”. The path starts from the user name. I.e. :-

    “[user_id]/files/Documents/….”

    Note the process is running as www-data user due to being the owner of all the files.

    The above is very time consuming. The preview generator has another option for just running on the files created after its last run. This is used to keep the thumbnails up to date. Its called “pre-generate”

    The general advice on the preview command is to run it as a system cron job. I used the code below to achieve this.

    #the following command starts the cron editor
    crontab -e
    
    #I then added the following line
    * */1 * * * docker exec -u www-data nextcloud /var/www/html/occ preview:pre-generate

    The is causing the generator to run once an hour. Again under the www-data user.

  • Docker updates

    So, most of my docker compose scripts are fairly specific, Most are using the :latest tags unless there is a specific reason for not doing so. Updating them can be carried out periodically by running the following

    #Once SSH'ed into the hosting server
    
    docker compose pull 
    
    #Alternatively, if using profiles
    
    docker compose --profile chosen-profile pull
    
    #If it does pull down any new versions, then stop the
    #current containers, build, then restart
    
    docker compose --profile chosen-profile down
    docker compose --profile chosen-profile build
    docker compose --profile chosen-profile up -d
    
    #For issues, leave off the -d switch to see startup messages. Failing that 
    #investigate the logs of the containers
    
    docker logs name-container