You can (and should) build an image containing your app. This could, if you like, be built on top of your shared rails image. Look up the docker build command and the Dockerfile system (and if you’ve found docker commit or docker export, don’t use those).
I don’t really understand the question. In addition to using Github for source control for your application, you can also store the Dockerfile in the repository. If you have a side repository of automation scripts, you should run git clone in a wrapper script, not in the Dockerfile.
If you don’t delete the container ,you won’t lost the files that you create. A better way ,you can use Volume to mount the host directory to container ,save the files in the volume directory,even though,you delete the container ,you won’t lost the files.