Docker environment for two similar projects - docker

How to set up Docker environment for development of two similar web projects, with different versions of the similar software?
Project A
Debian Wheezy
Apache 2.2
MySQL 5.6
PHP 5.4
Project B
Ubuntu LTS latest
Apache 2.4
MySQL 5.7
PHP 7.0
Both projects
volume for web application source files
apache mods: rewrite etc.
editable vhost.conf file
phpMyAdmin
packages like git-core, vim-nox, mc, phing, phpunit, openssh
persistent database, initally populated from .sql file
UTF8 by default
What is the best way to do it assuming, that:
there will be more similar projects developed at once on my host in the future
I want to save maximum resources (disk space, memory and cpu)
I prefer using base images (eg. httpd:2.2 than easyone:lamp), because I have to emulate environment already present on production machines

Related

How do I implement XAMPP and Docker side-by-side in Windows 10

I recently ran into the issue where I was working on two Laravel projects: one using Docker, the other using XAMPP. I started my Docker project earlier, so I gave it access to port 3306.
When I went to implement the XAMPP project, I tried editing all the DB settings in the proper places to use the port 3308 so that it didn't collide with my DB docker container. Problem was, now I couldn't connect to phpMyAdmin. I was receiving errors that the settings were incorrect. So what was the solution?
The solution was to reset all of my settings to 3306, docker-compose down my Docker project, and then restart the XAMPP services. Worked like a charm.
So I'll note a couple things:
It seems like phpMyAdmin assumes it has access to 3306 even if you've changed your settings in config.inc.php.
Unrelated to this precise problem, I discovered that XAMPP's PHP version was different than what was installed on my Windows machine, which meant that I had two php.ini files. My php-cli was using the C/Program Files/PHP/php.ini, whereas XAMPP was using the XAMPP php.ini. While the XAMPP php.ini had the correct extensions uncommented, I needed to manually uncomment the appropriate extensions in the php-cli ini file. If you have xampp, go to the command line and use php --ini to check where your CLI ini file is located.
I suggest to try devilbox
The Devilbox is a modern and highly customisable dockerized PHP stack supporting full LAMP and MEAN and running on all major platforms. The main goal is to easily switch and combine any version required for local development. It supports an unlimited number of projects for which vhosts, SSL certificates and DNS records are created automatically. Reverse proxies per project are supported to ensure listening server such as NodeJS can also be reached. Email catch-all and popular development tools will be at your service as well. Configuration is not necessary, as everything is already pre-setup.

Is it possible to reference an SDK ( or any folder ) in a Docker Container from the Host computer?

Short description:
Is it possible to reference an SDK ( or any folder ) in a Docker Container from the Host computer?
Long description:
My team and I work in different environments ( Windows & Mac ) and on different stacks ( Asp .Net MVC / Elixir & Phoenix )
I'm trying to help everyone by creating separate Docker Stacks for each solution ( or group of projects )
What I have been able to do is set up the Docker Stacks so that each solution can be run in 1 or more Docker Containers and the developers can work on the code locally ( using direct host path mounts/volumes ) using an IDE of their choosing.
The issue is different solutions use different SDKs or even different versions of the same SDKs.
So what I would like to do is it up so that anyone in the team could reference the SDK installed on the Docker Container instead of installing the SDKs and each version of the SDKs they need for all the projects.
As far as I can tell, if I create a host mount binding, it will overwrite what's in the container with what's in the host, but I'd like to do it the other way round, I'd like to create a binding between the Docker Container and the Host and have the contents in the Docker Container show up in the Host.
Is this possible? Is there a better way to achieve this?
SDK images from vendors (e.g. asp.net core SDK images from Microsoft) best recommended compile/build time purpose and its lightweight version recommended for runtime in hosting/deployment environment.
Sole purpose of compile/build SDK images is for creating docker runtime images at build stage especially if target runtime OS (linux) is different than development machine OS e.g. Windows. If used efficiently with multistage builder pattern inside dockerfile, can create much lightweight runtime images for hosted environments.
e.g. aspnet.core SDK images used for building docker images and then run locally with host:guest port mapping. But if the dev machine OS is any linux distro then using SDK images is better as you can test validate in multiple SDK images. And these images just need exact name and docker deamon would download auto and use whenever required - that's it but certainly would needs good IDE orchestration support e.g. Visual Studio provides for docker based development on windows 10. or-else simply use docker CLI for build run.
Hope this helps clarify your need if not a solution

docker, vagrant sandboxes in php development

I have a missunderstanding and i want to find the best approach of a development sandbox environment for a PHP project.
I have a github repo that will host the code , .php, .js (will using webpack with babel), .scss files and different machines for development (windows, mac, ubuntu) .
I want to be able to pull the code from git hub , run a command (like vagrant up) and start a VM / container / sandbox with apache2 , php, nodejs that will run to parse .scss files and .js files into one and then be able to start the server on every platform without having to run gulp locally on developers PC, and then have the XAMPP installed with the correct path for apache2 http folder.
What would be the best approach ? To use vagrant VM with a file config on the repo or docker containers ?
I just want to simplify the development experience and to have this automated tools that start a server, compile sass and babel js.
Thank you
While I am a big Docker fan, it isn't always the right tool for the job. Docker has principals like immutability and single-service-per-container that probably won't work well for what you're looking to do without a learning curve.
There is a great open-source Vagrant tool called PuPHPet that make configuring a development environment straightforward.
https://puphpet.com/
From the PuPHPet web site you can configure an image with Apache2, PHP, and NodeJS via their wizard and it will generate a Vagrant file that you to run locally on your workstation. This way you can have all the software you need, without having to deal with installing/maintaining it yourself. It also supports installing databases, queues, and mail applications, should you need them.
For your scenario, I would clone the code from Github onto your workstation (not the VM) and mount it using Synced Folders against Vagrant, but still directly accessible by your IDE.

Is it possible to devep web applications (PHP/Ruby) using Docker without PHP/Ruby on host?

As in the question. Can you actually use Docker on top of Linux system (Ubuntu) that has NO php or ruby installed? I use postgres image for database and (of course) postgres package is not installed on my host.
I wonder if it is possible to use containers for development. How to overcome lack on rails new/rails g on host?
Docker environment it's completely independent of your host - they have the own library, packages installed inside of them. If you want to run ruby/php inside docker, just download proper image which contains ruby/php or build own image.
For ruby check this link: https://hub.docker.com/_/ruby/

Do I need to install Tomcat and MySQL on the Linux server to deploy Grails app?

My Grails app is based on
Gradle with Grails 2.4.4,
Tomcat plugin 7.0.55,
and MySQL plugin(mysql:mysql-connector-java:5.1.29).
Do I need to install Tomcat on the server?
Do I need to install MySQL on the server?
Both Tomcat and MySQL are not installed on dev environment(on my PC), but it seems working.
Container
While all the other answers pointed out, that you need already a container (which of course is true) there is also the option to use one of the "standalone" plugins (like e.g. https://grails.org/plugin/standalone). This will package your app as a fat jar, where the container and your app are part of a jar, that you simply run by java -jar myapp.jar (of course your would integrate that into your regular startup scripts on the server).
This is in general no bad option, since many WAR-deployed apps don't need any of the full blown container features anyway and you would be able to configure everything in place for your workload and don't have to compromise for all running wars (or your ops team). On the downside, if there is a security problem etc. with the container you would have to roll a new jar.
/With grails 3, which uses Spring Bootstrap, this even is a default option, since the preferred way of deploying. Spring Boot 1.2 supports Tomcat, Jetty, and Undertow by default./
Database
You can use a MySQL from "somewhere" else. But this is nitpicking, since you really need a MySQL somewhere (BTW: you really should start using MySQL also for your dev env, or you will be in for a few surprises once you put your stuff over to production).
Also be aware, that you can also keep using your H2 (see your datasource config) with files. This is an OK option (that saves you from installing a DB server) for small amounts of data you are storing and also there are other free database servers like PostgreSQL.
Obviously you have to install mysql and tomcat on the server.
During development you run grails from console, so you dont need tomcat as it will use embedded tomcat but still you need to have mysql installed, if you want to use mysql.
But on production, you create a war of your app using 'grails war command' and you deploy this war to a web container just like any other war, so you need tomcat and you will need mysql installed too.
In one word answer is 'Yes'.
Fact is when you are in development environment grails uses as an embedded tomcat server provided by the 'Apache Tomcat plugin' which version corresponds to grails version.
You've not installed mysql and you claimed 'it seems working'. That's funny! But it's not mysql who is working without being installed(!), rather it's also an integrated database provided by the 'H2 Database Plugin'.
So, when you'll deploy your grails app in Linux or another server certainly you need a tomcat server to handle user request to that app and a database where your data will be saved.

Resources