You can divide the line into three segments. The line is divided by the two planes of the bottom and top disks of the cylinder. See the image below (1) for example.
Each segment will find the minimum distance independently from each other, and only the minimum distance between all three segments will be chosen. To calculate the minimum distance of each segment, do:
First line segment (blue line): calculate the minimum distance between this segment and the bottom disk of the cylinder (I'm still using an iterative numerical method here using the distance between a point and a disk as objective function).
Second line segment (green line): project this line segment and the cylinder to the plane orthogonal to the main axis of the cylinder (as pointed by @Stefano). Find the point on this projected line that is closest to circle created by the cylinder projection.
Third segment (red line): same as the first segment, but now use the top disk.
Problem with this approach: Imagine you have a line that is really small, almost like a single point, direct below the top disk, inside the cylinder that never crosses to the top side. This approach will calculate the minimum distance as per the
Second segment before, (distance circle and line), but its wrong because the minimum distance should be from this line segment to the top disk.