Automating the creation of an Apache virtual-host file specifically
This has already been covered a bit in the comments, but I figured I'd lay out a more extensive answer.


  Is there a way to automate that / shorten the amount of lines code (the actual script-file is much bigger in principle), maybe even from some built-in behavior in Apache itself and without involving further software?


You can use a2ensite as a replacement for your very last line, the ln; all it does is set up symlinks into /etc/apache2/sites-enabled, which is where Apache httpd looks by default for configuration.  Some details may vary by distribution.

However, this only changes your script a tiny bit.  There are much larger problems you have to address.

First, I'll mention that no, Docker is almost certainly not the solution you want.  Docker works best when used in a container orchestration layer like Kubernetes, and while I can easily imagine an architecture with a single Docker image that takes in parameters to create different vhosts, it's a much more complicated system than your presumably one-host system and requires substantial changes to how everything works.  Docker is a hip new thing, but what many people do not realize is that it solves a set of well-understood problems and creates a set of new, poorly-understood ones, and it's likely that you don't have the problems that such an architecture would solve.  So let's set that aside for now.

The first problem you have is that you're writing Apache configuration (primarily) by hand, with templating in bash and limited validation.  In reality in your example this isn't a big deal since it's a small and simple config, but it's easy to start this way and end up with a large block of sed and ed commands (this I know from experience).

The larger problem is in how ephemeral your changes are.  You configure all these vhosts, great.  Then your server dies.  What happens?  You're probably going to spend a lot of time trying to rebuild it.  Hopefully you have a recent backup to help, but the point here is that the last few decades we've settled into this idea of treating configuration the same way as code - rather than setting things up by hand, you write all of your configuration into text files and a program translates that into configuration on the server.  This has a multitude of benefits, including backups, code review, and a history of changes that you can look back on.  Most configuration management tools also provide convenient abstraction layers.  Here is an example that lays out how to translate an Apache vhost file into an Ansible template, and then you only need to add new entries to the variable list and rerun the configuration.  When it comes to things like your database passwords, those too can be stored and version-controlled in Ansible Vault or a similar product.