If so, how would enemy forces have known these ships were carrying supplies and/or troops?
Yes, they've been fired on multiple times, mainly in the First and Second World Wars, but also in the so-called 'Tanker War' of the Iran-Iraq war. Most of the time, the point isn't to destroy the supplies or troops the ships are carrying, but rather to destroy the ships themselves, paralysing the defender's economic ability.
At first, commerce raiding was governed by Prize Rules. These aimed to ensure that only acceptable targets were sunk, and in a matter that was unthreatening to life - passenger ships could never be sunk, merchants could only be sunk if their crew was placed in a position of safety beforehand, and only those ships that posed an immediate threat to the attacker could be sunk without warning. Neutral ships could only be attacked if they had been inspected, and contraband (mainly military supplies) found. All attempts should be made to capture, rather than sink ships. However, as new technologies became available, these rules became very difficult to follow. The radio meant that any ship could pose an imminent threat to a raider, calling down hunters to harry them. The submarine was hugely useful for commerce raiding, but found it difficult to follow the rules. Following them meant forgoing the submarine's prime advantage, its ability to remain hidden.
During the First World War, both Great Britain and Germany attempted to carry out blockades on the other. The British used auxiliary cruisers to carry out a distant blockade, in near scrupulous adherence to prize rules. The Germans, with their surface forces bottled up in the North Sea by the Royal Navy, used submarines. At first, these attempted to follow Prize Rules, to limited effect against merchant ships. In 1915, the Germans introduced a policy of unrestricted submarine warfare, allowing submarines to attack targets in any manner they saw fit. This was very successful, sinking around 100,000 tons of shipping each month. However, due to the diplomatic backlash after the sinkings of the liners Lusitania, Arabic and Ancona, this policy was rescinded by the start of 1916. The policy was resumed in 1917, and was a major factor in bringing America into the war. With more submarines available, and no restrictions on their behaviour, the German U-boat offensive caused heavy losses to British shipping before countermeasures could be implemented.
In the Second World War, unrestricted submarine warfare was carried out by all involved powers. Germany again tried to cut the sea lanes between Britain and the rest of the world. Many merchant ships would be sunk, but increased construction in American yards made up for the shortfall. The U-boats had most success early in the war, and again in 1942 after America entered the war. By the end, airpower, sonar, and improved anti-submarine weapons had all but neutralised the U-boat threat. The British carried out a relatively successful campaign against German and Italian shipping to North Africa in the Mediterranean, and had less significant operations in the North Sea and against Japan. The USSR carried out submarine attacks against German shipping in the Baltic Sea. The Americans fought a wildly successful submarine campaign against Japan. While initially hampered by poor torpedoes, by the end, they had all but cut off Japan from oil supplies, and had reduced the average ration to near starvation levels. The Second World War did, however, show the possibility that unrestricted submarine warfare could lead to serious losses of innocent life. The sinking of the Wilhelm Gustloff by a Soviet submarine claimed 9,300 lives, mostly civilians. Several ships, including the British Laconia and Japanese Junyo Maru were sunk while carrying POWs, with serious loss of life.
The Tanker War is unusual in that it didn't involve submarines. Instead, it was carried out using aircraft, ships and missiles. Both Iran and Iraq wished to prevent the other from exporting oil. To do so, they carried out attacks on merchant ships and tankers in the other's waters. This included attacks on neutral ships, such as the Seawise Giant, one of the largest ships ever built. In some cases, ships were attacked while moored at loading points and refineries, such as Iran's Kharg Island. Over 500 merchant ships were attacked, and 430 sailors killed. The attacks provoked a strong response from neutral nations, with the Americans and Soviets escorting convoys through the Persian Gulf and British and French ships patrolling it to protect merchants.