Extending Official Docker Images with Dockerfile

Sometimes, packages you want are not built into the images developers prepare for you.

You don’t need to rebuild everything from scratch. Most of the time, you can extend an official image, install what you need, and run the upstream entrypoint as-is.


Example: Add FFmpeg to Nextcloud

Nextcloud can generate better previews (especially for videos) when ffmpeg is available inside the container.

1. Create a Dockerfile

Create a Dockerfile next to your docker-compose.yml:

Dockerfile
FROM nextcloud:apache

# Install ffmpeg (Debian-based Nextcloud image)
RUN apt-get update \
  && apt-get install -y --no-install-recommends ffmpeg \
  && rm -rf /var/lib/apt/lists/*
Code language: Dockerfile (dockerfile)

Notes:
• FROM nextcloud:apache keeps the official base.
• –no-install-recommends reduces bloat.
• rm -rf /var/lib/apt/lists/* keeps layers smaller.

2. Use it in docker-compose

Point your Nextcloud service to the Dockerfile:

Dockerfile
services:
  app:
    build: .
    image: my-nextcloud-with-ffmpeg:latest
    ports:
      - "8080:80"
    volumes:
      - nextcloud_html:/var/www/html
    depends_on:
      - db
      - redis
Code language: Dockerfile (dockerfile)

3. Build + verify

Bash
docker compose build app
docker compose up -d
docker compose exec app ffmpeg -version
Code language: Bash (bash)

If you see the version output, it’s installed.

4. (Optional) Confirm Nextcloud is using previews

In Nextcloud, enable or confirm preview settings as needed, then trigger video thumbnail generation by browsing a folder containing videos (or running your preview generator job).