         See #{build_log_path()}.
         """)
     end
+  end
+
+  defp set_volume_permissions(pkg) do
+    {_dockerfile, image} = config(pkg)
+
+    # (chown) 
+    #   Set the permissions of the build volume
+    #   to match those of the host user:group.
+    # (--rm)
+    #   Remove the container when finished.
+    args =
+      [
+        "run",
+        "--rm",
+        "-w=#{@working_dir}"
+      ] ++ mounts(pkg) ++ [image | ["chown", "#{uid()}:#{gid()}", @working_dir]]
+
+    case Mix.Nerves.Utils.shell("docker", args) do
+      {_result, 0} ->
+        :ok
+
+      {result, _} ->
+        Mix.raise("""
+        The Nerves Docker build_runner encountered an error while setting permissions:
+
+        #{inspect(result)}
+        """)
+    end
+  end
+
+  defp uid() do
+    {uid, _} = System.cmd("id", ["-u"])
+    String.trim(uid)
+  end
+
+  defp gid() do
+    {gid, _} = System.cmd("id", ["-g"])
+    String.trim(gid)
   end
 
   defp end_of_build_log() do

        "-a",
        "stdout",
        "-a",
        "stderr"
      ] ++ mounts(pkg) ++ ssh_agent() ++ [image | cmd]

    case Mix.Nerves.Utils.shell("docker", args, stream: stream) do

  # Helpers

  defp run(pkg, cmd, stream) do
    set_volume_permissions(pkg)

    {_dockerfile, image} = config(pkg)

    args =
