Usando o comando docker cp
, o script pode ser reescrito da seguinte forma:
HOSTIP="192.168.1.100"
PORT="62514"
set -e
CONTAINERID=$(sudo docker run -d ubuntu:14.04 /bin/bash -c "\
sed -i -e 's/# deb/deb/g' /etc/apt/sources.list; \
cat /etc/apt/sources.list; \
apt-get update; \
apt-get install --yes --force-yes git python-minimal; \
git clone https://github.com/mpv-player/mpv-build.git; \
cd mpv-build/; \
./update; \
apt-get install --yes --force-yes devscripts equivs; \
rm -f mpv-build-deps_*_*.deb; \
mk-build-deps -i -t \"apt-get --yes --force-yes --no-install-recommends\"; \
./build -j\$(nproc); \
echo \"From container: done building!\" | nc $HOSTIP $PORT; \
nc -v -l $PORT")
CONTAINERIP=$(sudo docker inspect $CONTAINERID|grep IPAddress|sed 's/.*IPAddress": "//'|sed 's/",$//')
echo "Started mpv-build container with Docker container ID: $CONTAINERID and IP: $CONTAINERIP"
echo "Waiting to hear from container that the build has finished..."
#listen on host. wait for container to connect and disconnect
nc -l $PORT
#copy file from running container, while it's listening for a connection with nc
sudo docker cp $CONTAINERID:/mpv-build/mpv/build/mpv ./
#connect to the listening socket in the container to make the container finish running
echo "bye" | nc $CONTAINERIP $PORT
echo "Done"
O netcat agora é usado apenas como uma espécie de mecanismo de mensagens, para o contêiner sinalizar para o host quando ele é feito (assim o host pode iniciar a cópia) e para o host sinalizar para o contêiner que ele fez copiando o arquivo (para que o contêiner possa sair).