If your friendly gym is low level, then sometimes there is a spare place and you can just put your pokemon in there. Look for an icon in the left bottom corner, with a plus sign, like this one:
If there are no spare spaces, that icon won't appear, and you will only see an icon in the right bottom corner which allows you to fight. You fight your team's gym like any other one, but by fighting it you raise the gym prestige (rather than take it down as it would be with a rival gym). Once you raised the gym prestige high enough, the level of the gym goes up and there will be a space for you to join the gym. You will notice how much gym prestige you raised, after every fight:
You typically get some gym prestige points even if you lose the fight. It is enough to bring down one pokemon to get some points - and you will do that easily given that your squad has six pokemon in it!
Don't worry too much about not being able to win! The worst that can happen is that your pokemon will faint and you will need to revive them, and then use some potion to restore their health. Pokemon don't die, so you won't lose them even if you do badly in a gym fight.
If you choose the right pokemon type, it is possible to win a battle even if your pokemon CP is half the CP of the opponent. Not only it is possible, but you will get more prestige points because of this, and you will create a new space in the gym faster! Go for it!