diff --git a/Dockerfile b/Dockerfile
index ce50d46fc1f2dce3dc8445fc1655590baf6f5244..67057af959d30c967cd56c2296c993748deaac27 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -29,5 +29,9 @@ ENV XDG_RUNTIME_DIR=/tmp
 ENV QT_QPA_PLATFORM=wayland
 ENV MAKEFLAGS=-j8
 
+# Keep Qt source code as part of the image to avoid duplication
+COPY scripts/clone-qt.sh /home/build/scripts/clone-qt.sh
+RUN scripts/clone-qt.sh
+
 COPY scripts/ /home/build/scripts
 CMD "./scripts/run.sh"
diff --git a/scripts/checkout-qt.sh b/scripts/checkout-qt.sh
new file mode 100755
index 0000000000000000000000000000000000000000..6d14317e30d35f480acdc9d849f813acb7ffe3ea
--- /dev/null
+++ b/scripts/checkout-qt.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -ex
+srcdir=$(pwd)/qt5
+qt5_rev=${QT_DOCKERTEST_QT5_REV:-5.11}
+
+git fetch --depth 1 origin "$qt5_rev"
+git checkout FETCH_HEAD
+git submodule update --init -- qtbase qtxmlpatterns qtdeclarative qtwayland
+
+if [[ -v QT_DOCKERTEST_QTWAYLAND_REV ]] ; then
+    cd "$srcdir/qtwayland"
+    git fetch --depth 1 origin "$QT_DOCKERTEST_QTWAYLAND_REV"
+    git checkout FETCH_HEAD
+fi
diff --git a/scripts/run.sh b/scripts/run.sh
index 15cfbb7bb24b43099c8c016b50f83b525eb1b091..7c86b7bd5ac7adb75effdd4215c0200af9e3492b 100755
--- a/scripts/run.sh
+++ b/scripts/run.sh
@@ -1,7 +1,9 @@
 #!/bin/bash
 set -ex
-time scripts/clone-qt.sh
-echo Finished cloning
+#time scripts/clone-qt.sh
+#echo Finished cloning
+time scripts/update-qt.sh
+echo Finished preparing sources
 time scripts/build-qt.sh
 echo Finished building
 time scripts/build-qtbase-tests.sh