1

I have created this repository on GitHub with something that I have developed so that by implementing docker I can easily obtain a setup lamp, but I would like to add some additional things to it, I don't know if something already exists or how to search or find what makes me lack

This is my project: https://github.com/arcanisgk/docker-lamp-stack
Prefered Host OS: Windows, secundary Ubuntu 24.04

I'm looking for something that allows me to build the docker containers with the commands to establish the following structure:

enter image description here

Can somebody help me?

New contributor
ArcanisGK507 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
6
  • 1
    Welcome ArcanisGK507! When you mention you are looking for "something", can you please clarify if you are looking for software, a web-app, or an API? If so, your question will likely be on-topic here. If not, perhaps we can direct you to another resource that may be helpful. Again, welcome! Sep 18 at 6:37
  • I am looking to improve my project setup, I do not know if this can be achieved by implementing some software, a web-app, or an API, since I think my scenario is quite specific, I think there may be people interested, in the end I am looking to recreate an environment development based on docker that, when implemented automatically, can display Local URLs and that the docker has all the expected utilities of a Linux server with a LAMP stack and other utilities such as cronjobs, etc., I know that my project is halfway there but I don't know which is "the right way" with docker. Sep 18 at 15:20
  • with the minimum of manipulation on the part of the users. or in other circumstances that customization, activation and deactivation of utilities is simple and intuitive, as I have tried to implement an .ENV file with these objectives and use a YML file for the deployment. Sep 18 at 15:22
  • I had deleted this post since another user of this and another site began to complain about having published it on two different sites, thinking they would fit together, my goal is not to post questions or meaningless things, the only thing I was looking for was guidance, but Apparently what was published was poorly seen and poorly received. Sep 18 at 15:24
  • 2
    My apologies for that other individual. They were out of line, and their comment has been deleted. Please don't let their negativity discourage you. Although that kind of behaviour may unfortunately be tolerated (and perhaps even encouraged) at other SE sites, we definitely don't allow that kind of unwelcoming and unfriendly behaviour in this SE community. You are always welcome here and are encouraged to contribute. Sep 19 at 0:56

2 Answers 2

2

After a day of research, I did not find a software, extension or API that solved my problem so I had to resort to scripting in the OS so I would consider that this question was solved more as a super user or programmer than with a recommended software; Even so, I do not consider this to be a definitive answer, so I consider that it can be improved with time and the contribution of other users.

To achieve the goal it was necessary to make some changes to the structure, we started with changes to the .env file:

    LH_URL="lh-2"
    LH_URL_HOST="127.0.0.1 ${LH_URL}.dock ${LH_URL}.pma.dock ${LH_URL}.revprox.dock"

then implement a very basic test .yml file, :

    version: '3'
    services:
      web:
        image: nginx
        container_name: ReverseProxy
        ports:
          - "80:80"
        networks:
          default:
            aliases:
              - lh-2.revprox.dock
        volumes:
          - ./reverse-proxy.conf:/etc/nginx/conf.d/reverse-proxy.conf
        command: [ nginx, '-g', 'daemon off;' ]

note: I am not interested in validating this part if it works since it was not the initial objective, this can be replaced by any yml file that works correctly

Finally, what really does the magic is a script for PowerShell:

# Feature to check if you are running as administrator
function Get-Administrator {
    $isAdministrator = (New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
    if (-not $isAdministrator) {
        $scriptPath = $MyInvocation.MyCommand.ScriptBlock.File
        Start-Process -FilePath 'powershell' -ArgumentList ('-File', $scriptPath) -Verb RunAs
        exit
    }
}

function Get-Pause {
    Read-Host "`n Press Enter to continue..."
}

function Set-EnvironmentVariables {
    $envFilePath = Join-Path -Path $scriptDirectory -ChildPath ".env"
    if (Test-Path $envFilePath) {
        Write-Host "`n Found the .env file in the following location: $((Get-Item -Path $envFilePath).FullName)"
        $envFileContent = Get-Content $envFilePath -Raw
        $envVariablesRaw = @{}
        $lineOrder = 0  # Inicializar el contador de orden
        $envFileContent -split [Environment]::NewLine | ForEach-Object {
            $line = $_.Trim()
            if ($line -match '^([^#=]+)=(.*)$') {
                $Key = $Matches[1]
                $Value = $Matches[2]
                $envVariablesRaw[$Key] = @{
                    'Value' = $Value
                    'Order' = $lineOrder  # Registrar el orden original
                }
                $lineOrder++
            }
        }
        $sortedEnvVariables = $envVariablesRaw.GetEnumerator() | Sort-Object { $_.Value.Order }
        $sortedEnvVariables | ForEach-Object {
            $var_name = $_.Key
            $var_value = $_.Value.Value
            $expresionRegular = '\$\{([^}]*)\}'
            $coincidencias = [System.Text.RegularExpressions.Regex]::Matches($var_value, $expresionRegular)
            foreach ($coincidencia in $coincidencias) {
                $textoEncontrado = $coincidencia.Groups[1].Value
                $env_value = [System.Environment]::GetEnvironmentVariable("INSTALL_$textoEncontrado")
                if (![string]::IsNullOrEmpty($env_value)) {
                    $var_value = $var_value.Replace($coincidencia, $env_value)
                }
                $var_value = $var_value -replace '"', ''
            }
            [System.Environment]::SetEnvironmentVariable("INSTALL_$var_name", $var_value, [System.EnvironmentVariableTarget]::Process)
        }
        if ([System.Environment]::GetEnvironmentVariable("INSTALL_LH_SYSTEM_NAME") -and [System.Environment]::GetEnvironmentVariable("INSTALL_LH_URL_HOST")) {
            return $true
        } else {
            Write-Host " LH_SYSTEM_NAME/LH_URL_HOST environment variables are not defined in the .env file"
            Get-Pause
            exit
        }
    } else {
        Write-Host " Environment Variables File not found."
        Get-Pause
        exit
    }
}

function Initialize-Docker {
    Write-Host "`n The docker service is being validated..."
    $dockerIsRunning = (docker ps 2>&1) -match '^(?!error)'
    if ($dockerIsRunning){
        Write-Host " The Docker Desktop and Service is running."
        Get-Pause
    } else {
        Write-Host " You must install and open Docker Desktop before using this program."
        Get-Pause
        exit
    }
    [Console]::Clear()
    Write-Host "`n Starting the downloading of image and construction of containers..."
    $env:DOCKER_HOST = "tcp://localhost:2375"
    docker-compose -f docker-compose.yml up -d --force-recreate
    Get-Pause
}

function Set-IpAddress {
    [Console]::Clear()
    $lh_url = [System.Environment]::GetEnvironmentVariable("INSTALL_LH_SYSTEM_NAME")
    $lh_url_host = [System.Environment]::GetEnvironmentVariable("INSTALL_LH_URL_HOST")
    $resolved_url_host = $ExecutionContext.InvokeCommand.ExpandString($lh_url_host)
    $resolved_url_host = $resolved_url_host -replace '"', ''
    $urls = $resolved_url_host -split ' '
    $web_server = $urls[0];
    $phpmyadmin = $urls[1];
    $proxy_container = "Proxy-Server"
    $ip_address = (docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $proxy_container)
    $ip_pattern = "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"
    if ($ip_address -match $ip_pattern) {
        $hosts_file = "${env:SystemRoot}\System32\drivers\etc\hosts"
        # you can implement ip container detection or set up 127.0.0.1
        # $host_entry = "$ip_address $resolved_url_host"
        $host_entry = "127.0.0.1 $resolved_url_host"
        $current_content = Get-Content $hosts_file -Raw
        $pattern = "(?ms)(# Developer Area Docker.*?# End of section)"
        if ($current_content -match $pattern) {
            $current_content = $current_content -replace $pattern, ("# Developer Area Docker`n$host_entry`n# End of section")
            Set-Content -Path $hosts_file -Value $current_content
            Write-Host "`n The URLs were successfully updated in the Host section!!!"
            Get-Pause
        } else {
            $current_content += "`n`n# Developer Area Docker`n$host_entry`n# End of section"
            Set-Content -Path $hosts_file -Value $current_content
            Write-Host "`n The Host section was added at the end of the hosts file!!!"
            Get-Pause
        }
    } else {
        Write-Host "`n Could not get container IP address $containerName."
        Get-Pause
        exit
    }
    [Console]::Clear()
    Write-Host "`n The installation of the development environment is complete."
    Write-Host "`n You will have access to urls:"
    Write-Host " web server with: http://$web_server/"
    Write-Host " phpmyadmin with: http://$phpmyadmin/`n"
    Get-Pause
}

Get-Administrator

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location -Path $scriptDirectory

$env_exit = Set-EnvironmentVariables
if($env_exit -eq $true){
    Initialize-Docker
    Set-IpAddress
}

This is my final version, with the implementation of the IP detection for the "ReverseProxy" container, this container will not undergo changes.

In the end I achieved the goal: saving the local URL entries of the Windows hosts file and at the same time validating and trying to run the build and configuration of the Docker environment.

If anyone is interested, you can add or update this entry with the script for MAC OS / Linux

New contributor
ArcanisGK507 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1

For both setup and startup tasks, take a look at the docker-compose tool.
For setup, the dependency structure (according to your diagram) can be defined with the depends_on directive.
For startup tasks, in particular the "restart" CLI directive. You could set restart to "always" for instance.

Of course you need to configure the containers in a way such that they run the services you want on startup. Something like a startup script in the [ENTRYPOINT] or appropriate commands in the update-rc.d directory (if you are running Linux containers).

1
  • Thank you for your comments, I have added some comments to the original post to improve the context of what I am looking for. Sep 18 at 15:49

Your Answer

ArcanisGK507 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.