tcolorbox defines special boxes for listings. One example is shown in Breaking pages in minted package and I've adapted to your code.
The mintedbox environment has three parameters, first and third are optional and second mandatory. With first parameter you can add options to minted options already declared inside the mintedbox. Second parameter is the languaje and third parameter allows you to declare new options for the tcolorbox part of mintedbox. With this third parameter you can add a title which with flip title option is attached to last fragment.
You probably want to have a "list of codes" and enumerated captions for these boxes, and references, and ... but this are other questions which you can ask one by one. By the way, memoir uses its own captioning system so captionof is not necessary.
In case following code doesn't work for you, update tcolorbox.
\documentclass{memoir}
\usepackage{minted}
\usepackage{setspace}
%\usepackage{xcolor} %<- already loaded by tcolorbox
\usepackage[most, minted]{tcolorbox}
%\tcbuselibrary{breakable} %<- loaded with `most` option
\definecolor{contessa}{HTML}{BF616A}
\DeclareTCBListing{mintedbox}{O{}mO{}}{%
enhanced,
listing only,
breakable,
minted language=#2,
minted options={%
linenos,
numbersep=5pt,
gobble=0,
tabsize=4,
breaklines=true,
mathescape,
framesep=2mm,#1},
% Appearance tweaks
top=0pt,
bottom=0pt,
left=0pt,
right=0pt,
arc=0pt,
colframe=contessa,
colback=contessa!10,
coltitle=contessa!30!black,
fonttitle=\bfseries,
colbacktitle=contessa!40,
flip title,
#3}
\begin{document}
Here is the %\autoref{lst:dockerfile2}
\begin{mintedbox}{docker}[title=Exemplo de códigos no \texttt{Dockerfile}]
FROM php:7.2-apache
# instalar as extensões PHP que precisas
RUN set -ex; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
libjpeg-dev \
libpng-dev \
; \
\
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
docker-php-ext-install gd mysqli opcache zip; \
\
# restaurar a lista do «manual» do apt-mark, pois esse "purge --auto-remove" removerá todas as dependências de construição
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*
# configurar as configurações recomendadas do PHP.ini
# veja https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
RUN a2enmod rewrite expires
VOLUME /var/www/html
ENV WORDPRESS_VERSION 4.9.8
ENV WORDPRESS_SHA1 0945bab959cba127531dceb2c4fed81770812b4f
RUN set -ex; \
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
# os tarballs de upstream incluem ./wordpress/, então isto nos dará /usr/src/wordpress
tar -xzf wordpress.tar.gz -C /usr/src/; \
rm wordpress.tar.gz; \
chown -R www-data:www-data /usr/src/wordpress
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]
\end{mintedbox}
\end{document}

Update Addition of labels for reference:
The new mintedbox declaration uses init options to automatically enumerate the code boxes and create a list of code. Now it has four parameters, the third one is a mandatory title for the box, labels for reference are included in fourth optional parameter, but it's easier to change the code and add them as a new mandatory (or optional) parameter.
I've added hyperref package to use \autoref command.
\documentclass{memoir}
\usepackage{minted}
\usepackage{setspace}
%\usepackage{xcolor} %<- already loaded by tcolorbox
\usepackage[most, minted]{tcolorbox}
%\tcbuselibrary{breakable} %<- loaded with `most` option
\usepackage{hyperref}
\definecolor{contessa}{HTML}{BF616A}
\DeclareTCBListing[%
auto counter,
number within=chapter,
list inside=code]%
{mintedbox}%
{O{}mmO{}}{%
enhanced,
listing only,
breakable,
minted language=#2,
minted options={%
linenos,
numbersep=5pt,
gobble=0,
tabsize=4,
breaklines=true,
mathescape,
framesep=2mm,#1},
% Appearance tweaks
top=0pt,
bottom=0pt,
left=0pt,
right=0pt,
arc=0pt,
colframe=contessa,
colback=contessa!10,
coltitle=contessa!30!black,
fonttitle=\bfseries,
colbacktitle=contessa!40,
flip title,
title=Code~\thetcbcounter: #3,
list text=#3,
#4}
\begin{document}
\tcblistof[\chapter]{code}{List of codes}
\chapter{Some code}
Here is the \autoref{code:lst:dockerfile2} and some more:
\begin{mintedbox}{docker}{Exemplo de códigos no \texttt{Dockerfile}}[label=code:lst:dockerfile2]
FROM php:7.2-apache
# instalar as extensões PHP que precisas
RUN set -ex; \
\
savedAptMark="$(apt-mark showmanual)"; \
\
apt-get update; \
apt-get install -y --no-install-recommends \
libjpeg-dev \
libpng-dev \
; \
\
\end{mintedbox}
\begin{mintedbox}{docker}{Exemplo de códigos no \texttt{Dockerfile}}[label=code:lst:dockerfile3]
docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
docker-php-ext-install gd mysqli opcache zip; \
\
# restaurar a lista do «manual» do apt-mark, pois esse "purge --auto-remove" removerá todas as dependências de construição
apt-mark auto '.*' > /dev/null; \
apt-mark manual $savedAptMark; \
ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
| awk '/=>/ { print $3 }' \
| sort -u \
| xargs -r dpkg-query -S \
| cut -d: -f1 \
| sort -u \
| xargs -rt apt-mark manual; \
\
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
rm -rf /var/lib/apt/lists/*
\end{mintedbox}
\begin{mintedbox}{docker}{Exemplo de códigos no \texttt{Dockerfile}}[label=code:lst:dockerfile4]
# configurar as configurações recomendadas do PHP.ini
# veja https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
RUN a2enmod rewrite expires
VOLUME /var/www/html
ENV WORDPRESS_VERSION 4.9.8
ENV WORDPRESS_SHA1 0945bab959cba127531dceb2c4fed81770812b4f
RUN set -ex; \
curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
# os tarballs de upstream incluem ./wordpress/, então isto nos dará /usr/src/wordpress
tar -xzf wordpress.tar.gz -C /usr/src/; \
rm wordpress.tar.gz; \
chown -R www-data:www-data /usr/src/wordpress
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]
\end{mintedbox}
\end{document}
The list of "codes":

and the code boxes:

\label\for\autoref? :-( – Oo'- Nov 29 '18 at 10:30\autoref? I commented out because it gave me an error in your MWE. Of course, tcolorboxes can be enumerated and labelled and referenced but this is not mentioned in your question. – Ignasi Nov 29 '18 at 10:40\autoref. The command\autorefwill forward and refer you to see the figure or the code. Does thetcolorboxwill automatically add it to the list of codes? What is the similar to\autoreffor tcolorbox? – Oo'- Nov 29 '18 at 11:23