diff --git a/contrib/ci/Dockerfiles/z3_base_ubuntu_14.04.Dockerfile b/contrib/ci/Dockerfiles/z3_base_ubuntu_14.04.Dockerfile
index ce78e7fb9..f6541a2c9 100644
--- a/contrib/ci/Dockerfiles/z3_base_ubuntu_14.04.Dockerfile
+++ b/contrib/ci/Dockerfiles/z3_base_ubuntu_14.04.Dockerfile
@@ -1,14 +1,12 @@
 FROM ubuntu:14.04
 
-RUN curl -SL https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb --output packages-microsoft-prod.deb && \
-    dpkg -i packages-microsoft-prod.deb && \
-    apt-get install apt-transport-https
-
 RUN apt-get update && \
     apt-get -y --no-install-recommends install \
+        apt-transport-https \
         binutils \
         clang-3.9 \
         cmake \
+        curl \
         doxygen \
         default-jdk \
         gcc-multilib \
@@ -26,8 +24,12 @@ RUN apt-get update && \
         python3 \
         python3-setuptools \
         python2.7 \
-        python-setuptools \
-        dotnet-sdk-2.1
+        python-setuptools
+
+RUN curl -SL https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb --output packages-microsoft-prod.deb && \
+    dpkg -i packages-microsoft-prod.deb && \
+    apt-get update && \
+    apt-get -y --no-install-recommends install dotnet-sdk-2.1
 
 # Create `user` user for container with password `user`.  and give it
 # password-less sudo access
diff --git a/contrib/ci/Dockerfiles/z3_base_ubuntu_16.04.Dockerfile b/contrib/ci/Dockerfiles/z3_base_ubuntu_16.04.Dockerfile
index efa1d5600..f4d9c873a 100644
--- a/contrib/ci/Dockerfiles/z3_base_ubuntu_16.04.Dockerfile
+++ b/contrib/ci/Dockerfiles/z3_base_ubuntu_16.04.Dockerfile
@@ -1,15 +1,13 @@
 FROM ubuntu:16.04
 
-RUN curl -SL https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb --output packages-microsoft-prod.deb && \
-    dpkg -i packages-microsoft-prod.deb && \
-    apt-get install apt-transport-https
-
 RUN apt-get update && \
     apt-get -y --no-install-recommends install \
+        apt-transport-https \
         binutils \
         clang \
         clang-3.9 \
         cmake \
+        curl \
         doxygen \
         default-jdk \
         gcc-multilib \
@@ -29,8 +27,12 @@ RUN apt-get update && \
         python3-setuptools \
         python2.7 \
         python-setuptools \
-        sudo \
-        dotnet-sdk-2.1
+        sudo
+
+RUN curl -SL https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb --output packages-microsoft-prod.deb && \
+    dpkg -i packages-microsoft-prod.deb && \
+    apt-get update && \
+    apt-get -y --no-install-recommends install dotnet-sdk-2.1
 
 # Create `user` user for container with password `user`.  and give it
 # password-less sudo access