         "-a",
         "stdout",
         "-a",
-        "stderr"
+        "stderr",
+        "--user",
+        "#{uid()}:#{gid()}"
       ] ++ mounts(pkg) ++ ssh_agent() ++ [image | cmd]
 
     case Mix.Nerves.Utils.shell("docker", args, stream: stream) do


    mounts = Enum.join(mounts(pkg), " ")
    ssh_agent = Enum.join(ssh_agent(), " ")
    cmd = "docker run --rm -it -w #{@working_dir} #{mounts} #{ssh_agent} #{image}"
    Mix.Nerves.Shell.open(cmd, initial_input)
  end


        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
