diff --git a/docker/mingw/Dockerfile b/docker/mingw/Dockerfile
index 2f522246d..176349839 100644
--- a/docker/mingw/Dockerfile
+++ b/docker/mingw/Dockerfile
@@ -18,18 +18,20 @@
# .
#
-FROM debian:testing
+FROM debian:stretch
ARG REPO=shadowsocks
ARG REV=master
-ADD docker/mingw/prepare.sh /
+ADD docker/mingw/apt.sh /
RUN \
- /bin/bash -c "source /prepare.sh && dk_prepare" && \
+ /bin/bash -c "source /apt.sh && dk_prepare" && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /build
+ADD docker/mingw/prepare.sh /
+
RUN /bin/bash -c "source /prepare.sh && dk_download"
ADD docker/mingw/deps.sh /
diff --git a/docker/mingw/apt.sh b/docker/mingw/apt.sh
new file mode 100644
index 000000000..fa2780f6c
--- /dev/null
+++ b/docker/mingw/apt.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+#
+# Functions for building MinGW port in Docker
+#
+# This file is part of the shadowsocks-libev.
+#
+# shadowsocks-libev is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# shadowsocks-libev is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with shadowsocks-libev; see the file COPYING. If not, see
+# .
+#
+
+# Exit on error
+set -e
+
+# Build steps
+
+dk_prepare() {
+ apt-get update -y
+ apt-get install --no-install-recommends -y \
+ mingw-w64 aria2 git make automake autoconf libtool ca-certificates
+}
diff --git a/docker/mingw/build.sh b/docker/mingw/build.sh
index fea0265bd..8ad6c001d 100644
--- a/docker/mingw/build.sh
+++ b/docker/mingw/build.sh
@@ -43,6 +43,7 @@ build_proj() {
--with-pcre="$dep" \
--with-cares="$dep" \
CFLAGS="-DCARES_STATICLIB -DPCRE_STATIC"
+
make clean
make -j$cpu LDFLAGS="-all-static -L${dep}/lib"
make install
diff --git a/docker/mingw/deps.sh b/docker/mingw/deps.sh
index 2e15a4a1a..95884498e 100644
--- a/docker/mingw/deps.sh
+++ b/docker/mingw/deps.sh
@@ -53,6 +53,7 @@ build_deps() {
# sodium
cd "$SRC/$SODIUM_SRC"
+ ./autogen.sh
./configure $args
make clean
make -j$cpu install
diff --git a/docker/mingw/prepare.sh b/docker/mingw/prepare.sh
index 728c03c01..9abf0b4be 100644
--- a/docker/mingw/prepare.sh
+++ b/docker/mingw/prepare.sh
@@ -48,9 +48,9 @@ MBEDTLS_SRC=mbedtls-${MBEDTLS_VER}
MBEDTLS_URL=https://tls.mbed.org/download/mbedtls-${MBEDTLS_VER}-apache.tgz
## Sodium
-SODIUM_VER=1.0.16
-SODIUM_SRC=libsodium-${SODIUM_VER}
-SODIUM_URL=https://download.libsodium.org/libsodium/releases/${SODIUM_SRC}.tar.gz
+SODIUM_VER=1.0.18
+SODIUM_SRC=libsodium-${SODIUM_VER}-RELEASE
+SODIUM_URL=https://github.com/jedisct1/libsodium/archive/${SODIUM_VER}-RELEASE.tar.gz
## PCRE
PCRE_VER=8.41
@@ -64,12 +64,6 @@ CARES_URL=https://c-ares.haxx.se/download/${CARES_SRC}.tar.gz
# Build steps
-dk_prepare() {
- apt-get update -y
- apt-get install --no-install-recommends -y \
- mingw-w64 aria2 git make automake autoconf libtool ca-certificates
-}
-
dk_download() {
mkdir -p "${SRC}"
cd "${SRC}"