Cheap and easy DevOps for developers (Docker, Ubuntu, Apache and Spring)
Today the trend in every company is to use a DevOps architecture as a magical solution for everything. Translated for the developer not only he has to build the software but deploy it as well.
The standard solutions are platforms like OpenShift or CloudFoundry. These solutions are oriented and affordable for companies but way too expensive for most of the developers that want to publish their ready to grow application.
To give an idea about the prices a small app running on a DevOps cloud solution (1 GB RAM) cost around $30 per month, with a basic VPS and docker only $3-5 (2GB RAM for more apps!).
What we need
- vps hosting of your choice
- ubuntu or other linux distribution
- your software
VPS and Docker
Install Docker on your server using the official Docker documentation or the instructions of your server provider. You can pull your own image or an image from dockerhub.com. For instance my Angular and Java demo
docker pull javaee/angular2-java-hello-world
to run the app on port 8080
docker run --name angular -d -p 8080:8082
If you prefer you can deploy directly your web app on the server but you risk to miss most of the fun. 😉
Create a VirtualHost
You will run multiple docker containers in server, for this reason is better to have a proxy that redirect the external requests to the correct applications.
www.angular.cafe -> localhost:8090
www.mycv.host -> localhost:8088
In ubuntu you have to install apache2
sudo apt-get install apache2 sudo apt-get install libapache-mod-jk
activate the features to use the proxy:
sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod ssl sudo a2enmod proxy_balancer
Create a file with your host configuration in the following path:
the file name suffix has to be .conf e.g.
sudo vi ./mydomain.conf
Apache Virtual Host configuration for Tomcat
# *.80 listen all the requests at the port 80 <VirtualHost *:80> # the following rules apply for the requests # to the www.mycv.host server ServerName www.mycv.host # aliases of our server name (answer to this calls too) ServerAlias *.mycv.host *.mycv.help # email of the administrator ServerAdmin webmaster@localhost # ProxyPreserveHost On # where to redirect the request to mycv.host ProxyPass / https://localhost:8080/ ProxyPassReverse / https://localhost:8080/ # root of the target (doesn't apply for tomcat) DocumentRoot /var/www </VirtualHost>
To activate this rule:
sudo a2ensite mydomain.conf _
Deactivate the default answering for the port 80 (apache welcome) :
sudo a2dissite 000-default-conf _
Restart your apache service
sudo /etc/init.d/apache2 restart
You can check the status of your service:
systemctl status apache2.service
Your application running on port 8080 (if Java based) is accessible at the url: mydomain.com, port 80.
If your application doesn’t answer from internet it is possible that the port 80 of your server is not closed. You can test in your server to see if the application is correctly deployed with:
If your terminal shows the content of your application home page it mean that the deploy is correct.
Continue … Docker publish and deploy, cheat sheet