Assuming you are using the official PHP Docker image...
# ---------------------------------------------------------------
# PHP Extension: Gearman
# Download Gearman PECL extension for Gearman supporting PHP 7
RUN apt-get -y --allow-unauthenticated install \
libgearman-dev
RUN cd /tmp \
&& git clone https://github.com/wcgallego/pecl-gearman.git \
&& cd pecl-gearman \
&& git checkout gearman-2.0.3 \
&& phpize \
&& ./configure \
&& make -j$(nproc) \
&& make install \
&& rm -r /tmp/pecl-gearman \
&& docker-php-ext-enable gearman
I updated this one a little: