Docker Community Forums

Share and learn in the Docker community.

Looking for a shell to manage multiple websites on a localhost

Hi. I’m looking for a shell or some kind of box solution to manage multiple websites on localhost. Something with proxy container and database containers, something that will automatically add and remove records to the host file of my machine. Do you follow me?

Let me put it others: you want to use multiple websites on a single webserver with vhosts (hostname or fqdn) and you want your /etc/hosts or local dns server updated.

You would absolutely love kubernetes and what external-dns is able to do with an ingress controller. If you run a local dns server, external-dns is able to fetch the hostname from ingress rules and update your dns server accordingly making the hostname immediatly available for your host’s name resolution.

Though, if k8s is too complicated, you could add labels (any key, value=hostname) to your container, register for container create/shutdown events (docker events or using the docker api) and write a handler that updates your /etc/hosts file accordingly or updates a local dns server via api whenever a container is created/shutdown that has the label you added.

Let’s Install XAMPP on Windows
Step 1: Download XAMPP
Start off by downloading the latest version of XAMPP from Apache Friends website. The current up-to-date version of XAMPP is 7.3.8 / PHP 7.3.8.

Note: If you’re using Linux or OSX, the installation steps are pretty much the same. Just make sure to download the appropriate version of XAMPP for your OS.

Step 2: Install XAMPP
Once downloaded, run the XAMPP installer file.

The XAMPP Setup Wizard

You might get a UAC warning before installation. Click OK and continue.
Select the components you want to install. If you’re planning to install a WordPress site with XAMPP, you only need Apache, MySQL, PHP, and phpMyAdmin. I’ll check all the components as I’d like to experiment with them later.

Choose the installation directory for XAMPP (default recommended).

Uncheck Learn more about Bitnami option. Bitnami provides all-in-one tools to install popular open source apps on top of XAMPP. This includes add-on modules for installing WordPress too. However, we’ll be installing it manually here.

You may be presented with a Windows Security Alert at the end of the installation. You need to whitelist Apache HTTP Server from your Windows Defender Firewall by clicking the Allow access button. Make sure to check the “Private networks, such as my home or work network” option. This is very important. XAMPP won’t work if you don’t check this and click Allow access.

Complete the setup and run XAMPP Control Panel.

Installation Note 1: Deactivate UAC under Windows Settings
You might be presented with a User Access Control (UAC) warning by Windows. Nothing to worry much. Just make sure that you don’t install XAMPP under your Program Files directory, as UAC can interfere with XAMPP’s writing permissions to this directory. The default installation directory is C:\XAMPP. So, if you don’t change it, you should be good.

If you want to learn how to deactivate UAC (not recommended unless absolutely necessary), Microsoft Windows support is a good place to start.

Installation Note 2: Deactivate Antivirus and/or Firewall Temporarily
Some antivirus or firewall programs can cause issues with your XAMPP installation. If that’s the case, it’s suggested that you deactivate them temporarily until XAMPP is installed successfully.

Read the XAMPP Windows FAQs page for more.

Step 3: Open the XAMPP Control Panel
The XAMPP Control Panel sports a simple user interface that lists all the modules of your local server. It allows you to Start/Stop individual modules, access their Admin area, Config files, and Logs with just a single click. Its bottom section also displays all your actions and errors (if any).

Apart from the options discussed above, the XAMPP Control Panel also features other buttons on its right side:

Config: to configure overall XAMPP settings
Netstat: display all active TCP connections (and ports) on your computer
Shell: starts XAMPP in a custom command line (CMD)
Explorer: opens the XAMPP root folder in Windows Explorer
Services: shows all Windows services under Microsoft Management Console
Help: links to Apache Friends Support Forum
Quit: quit XAMPP Control Panel (the server will continue to run in the background)
Step 4: Start Apache and MySQL Modules
Click the Start button beside Apache module. If everything’s set correctly, your Apache server should start successfully under ports 83 and 443.

I knew someone will bring up Kubernetes but I didn’t expect it to be the first reply :slight_smile: I didn’t work with Kubernetes yet but I’ll keep it in mind as an option, thanks.

At the moment I have multiple local hosts with docker based on jwilder/nginx-proxy and it works pretty neat but I was wondering if there are some tools out there to improve my workflow.

lewish95 , does XAMPP use Docker?
P.S. Actually I’m Linux user.

jwilder`s nginx-proxy and traefik (which I prefer) both use ENV’s or labels to define reverse proxy rules. Typicaly those include the domain as well, so you could read them from the event and modify your /etc/hosts accordingly

This is an example how a simple event handler could look like:

docker events --format '{{json .}}' | while read entry; do
  if [ "${show_full_json}" == "true" ]; then
    echo "${entry}" |  jq '.'
    type=$(echo "${entry}" |  jq -r '.Type')
    if [ ${type} == "container" ]; then
      action=$(echo "${entry}" | jq -r '.Action')
      scope=$(echo "${entry}" | jq -r '.scope')
      container_id=$(echo "${entry}" | jq -r '.id')
      image=$(echo "${entry}" | jq -r '.from')
      #actor_id=$(echo "${entry}" | jq -r '.Actor.ID')
      actor_attr_image=$(echo "${entry}" | jq -r '.Actor.Attributes.image')
      case ${action} in
        exec_create:*) echo "create: ${image} ${container_id} ${scope}"
                       docker inspect ${container_id} --format '{{json .Config.Env}}' | jq
        exec_start:*)  echo "start: ${container_id} ${actor_attr_image}";;
        exec_die*)     echo "die: ${container_id} ${actor_attr_image}";;

I wrote this example handler in roughly 30 minutes, just for the sake of giving it a try myself :slight_smile:

Due to easier parsing of json content, the docker events are formated as json. To process the output the command jq needs to be installed on the system. I provided some examples on how to read single values from the json. The json output will include the container labels, but not the envs. For that I added an example in exec_create*) for how to get additional information from the running container.

Good luck!

1 Like

I picked the wrong events and changed from echo "${entry}" | jq .. to jq .. <<< ${entry}.

Here is the correction

docker events --format '{{json .}}' | while read entry; do
  if [ "${show_full_json}" == "true" ]; then
    jq '.' <<< ${entry}
    type=$(jq -r '.Type' <<< ${entry})
    if [ ${type} == "container" ]; then
      action=$(jq -r '.Action' <<< ${entry})
      scope=$(jq -r '.scope' <<< ${entry})
      container_id=$(jq -r '.id' <<< ${entry})
      image=$(jq -r '.from' <<< ${entry})
      actor_attr_image=$(jq -r '.Actor.Attributes.image' <<< ${entry})
      case ${action} in
        start)  echo "start: ${image} ${container_id} ${scope}"
                       docker inspect ${container_id} --format '{{json .Config.Env}}' | jq
        die)     echo "die: ${container_id} ${actor_attr_image}";;
1 Like

Just in case someone is interesting:

I made shell for myself:

It doesn’t look super cool but it works like a charm - I’m in control of my localhost containers and domains in *.local zone, I can create new project in a second and I don’t have any dependencies to backfire except Docker itself.