DockerEnv sets environment variables for a docker-compose run.
()
| 2772 | |
| 2773 | // DockerEnv sets environment variables for a docker-compose run. |
| 2774 | func (app *DdevApp) DockerEnv() map[string]string { |
| 2775 | uidStr, gidStr, username := dockerutil.GetContainerUser() |
| 2776 | |
| 2777 | // Warn about running as root if we're not on Windows. |
| 2778 | if uidStr == "0" || gidStr == "0" { |
| 2779 | util.WarningOnce("Warning: containers will run as root. This could be a security risk on Linux.") |
| 2780 | } |
| 2781 | |
| 2782 | // For Codespaces/Devcontainer |
| 2783 | // * provide default host-side port bindings, assuming only one project running, |
| 2784 | // but if more than one project, can override with normal config.yaml settings. |
| 2785 | // Codespaces stumbles if not on a "standard" port like port 80 |
| 2786 | if nodeps.IsDevcontainer() { |
| 2787 | if app.HostWebserverPort == "" { |
| 2788 | app.HostWebserverPort = "80" |
| 2789 | } |
| 2790 | } |
| 2791 | if nodeps.IsDevcontainer() { |
| 2792 | if app.HostWebserverPort == "" { |
| 2793 | app.HostWebserverPort = "8080" |
| 2794 | } |
| 2795 | if app.HostHTTPSPort == "" { |
| 2796 | app.HostHTTPSPort = "8443" |
| 2797 | } |
| 2798 | if app.HostDBPort == "" { |
| 2799 | app.HostDBPort = "3306" |
| 2800 | } |
| 2801 | if app.HostMailpitPort == "" { |
| 2802 | app.HostMailpitPort = "8027" |
| 2803 | } |
| 2804 | if app.HostXHGuiPort == "" { |
| 2805 | app.HostXHGuiPort = nodeps.DdevDefaultXHGuiHTTPPort |
| 2806 | } |
| 2807 | app.BindAllInterfaces = true |
| 2808 | } |
| 2809 | |
| 2810 | isWSL2 := "false" |
| 2811 | if nodeps.IsWSL2() { |
| 2812 | isWSL2 = "true" |
| 2813 | } |
| 2814 | |
| 2815 | // DDEV_HOST_DB_PORT is actually used for 2 things. |
| 2816 | // 1. To specify via base docker-compose file the value of host_db_port config. And it's expected to be empty |
| 2817 | // there if the host_db_port is empty. |
| 2818 | // 2. To tell custom commands the db port. And it's expected always to be populated for them. |
| 2819 | dbPort, err := app.GetPublishedPort("db") |
| 2820 | dbPortStr := strconv.Itoa(dbPort) |
| 2821 | if dbPortStr == "-1" || err != nil { |
| 2822 | dbPortStr = "" |
| 2823 | } |
| 2824 | if app.HostDBPort != "" { |
| 2825 | dbPortStr = app.HostDBPort |
| 2826 | } |
| 2827 | |
| 2828 | // Figure out what the host-webserver (host-http) port is |
| 2829 | // First we try to see if there's an existing webserver container and use that |
| 2830 | hostHTTPPort, err := app.GetPublishedPort("web") |
| 2831 | hostHTTPPortStr := "" |