There are many ways.
Natural dyes use use basic plants and put them in water or oil with salts to enable fibers to take up colors from the plants such as indigo or onions or berries or other bright plant materials.
For minerals, one must dissolve the minerals first to ensure that they can penetrate the fabrics so again use alcohol or oil or wax or other solvent to enable a mineral to adhere to the liquid and then penetrate the fabric.
The fabric itself may be natural fiber so easy to die, such as cotton or silk in which case a simple soaking will do for however long a particular shade is desired. Waxing to prevent areas from color (such as tye dying) is often used) or mud cloth mixes.
For artificial fibers such as nylon, the colors must be made part of the actual manufacturing process, so one has to figure out how to add the dye into the mix when the original mix is heated to boiling or vaporization, so I am not certain of that process.