# Custom Docker images

The Core-FFmpeg bundle uses Docker's multi-stage process so that FFmpeg and the Core can be updated and maintained independently.

When building the Core-FFmpeg bundle, an FFmpeg image is used. The previously created Golang libraries and folder structures are copied into this image.

This process speeds up the creation of the final Core-FFmpeg bundle, as existing or previously created images can be used, and compiling all the code is no longer required.

**The following base images are available:**

* docker.io/datarhei/base:alpine-ffmpeg-latest
* docker.io/datarhei/base:alpine-ffmpeg-rpi-latest
* docker.io/datarhei/base:ubuntu-ffmpeg-cuda-latest
* docker.io/datarhei/base:ubuntu-ffmpeg-vaapi-latest
* docker.io/datarhei/base:alpine-core-latest
* docker.io/datarhei/base:ubuntu-core-latest

**Specific versions are available on the Docker website:**

{% embed url="<https://hub.docker.com/r/datarhei/base/tags>" %}

##

## 1. Create a custom FFmpeg image

### 1.1 Clone the FFmpeg build files &#x20;

```bash
git clone github.com/datarhei/ffmpeg
```

#### Repository

{% embed url="<https://github.com/datarhei/ffmpeg>" %}

### 1.2 Switch to the cloned folder

```bash
cd ffmpeg
```

### 1.2 Change a Dockerfile

{% code title="Edit: Dockerfile.alpine" %}

```bash
...
RUN cd /dist/ffmpeg-${FFMPEG_VERSION} && \
  patch -p1 < /contrib/ffmpeg-jsonstats.patch && \
  patch -p1 < /contrib/ffmpeg-hlsbitrate.patch && \
  ./configure \
  --extra-version=datarhei \
  --prefix="${SRC}" \
  --extra-libs="-lpthread -lxml2 -lm -lz -lsupc++ -lstdc++ -lssl -lcrypto -lz -lc -ldl" \
  --enable-nonfree \
  --enable-gpl \
  --enable-version3 \
  --enable-postproc \
  --enable-static \
  --enable-openssl \
  --enable-libxml2 \
  --enable-libv4l2 \
  --enable-v4l2_m2m \
  --enable-libfreetype \
  --enable-libsrt \
  --enable-libx264 \
  --enable-libx265 \
  --enable-libvpx \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --disable-ffplay \
  --disable-shared && \
  make -j$(nproc) && \
  make install
...
```

{% endcode %}

{% hint style="info" %}
Dockerfile without **--disable-debug** and **--disable-doc.**
{% endhint %}

### 1.3 Build a custom image&#x20;

```bash
./Build.sh default
```

**Arguments:**

* **default**\
  Dockerfile: Dockerfile.alpine\
  Image name: datarhei/base:alpine-ffmpeg-latest
* **rpi**\
  Dockerfile: Dockerfile.alpine.rpi\
  Image name: datarhei/base:alpine-ffmpeg-rpi-latest
* **cuda**\
  Dockerfile: Dockerfile.ubuntu.cuda\
  Image name: datarhei/base:ubuntu-ffmpeg-cuda-latest
* **vaapi**\
  Dockerfile: Dockerfile.ubuntu.vaapi\
  Image name: datarhei/base:alpine-ffmpeg-vaapi-latest

##

## 2. Create a custom Core image

### 2.1 Clone the Core build files

```bash
git clone git@github.com:datarhei/core.git
```

#### Repository

{% embed url="<https://github.com/datarhei/core>" %}

### 2.2 Switch into the cloned folder

```bash
cd core
```

### 2.3 Build a custom image

```bash
docker build -t datarhei/base:alpine-core-latest .
```

##

## 3. Create a custom Core-FFmpeg bundle

You can find the Dockerfile for the bundle (Dockerfile.bundle) in the cloned Core repository.

### 3.1 Build a custom image

```bash
docker build \
    -f Dockerfile.bundle \
    --build-arg CORE_IMAGE=datarhei/base:alpine-core-latest \
    --build-arg FFMPEG_IMAGE=datarhei/base:alpine-ffmpeg-latest \
    -t core-bundle:dev .
```

{% hint style="info" %}
Docker supports multi-architecture images via  **--platform linux/amd64,linux/arm64,linux/arm/v7.**
{% endhint %}
