WSL2 uses Docker to run ManageIQ (including Systemctl installation, script configuration agent and Docker port mapping)

WSL2 uses Docker to run ManageIQ (including Systemctl installation, script configuration agent and Docker port mapping)

Use the image provided by the ManageIQ project on the Docker Hub to test the ManageIQ running in the Docker container. It solves some problems in using WSL2: starting with systemd, accessing the host windows agent in WSL2, installing ManageIQ and mapping the port to the windows host.

reference material:

[DamionGans/ubuntu-wsl2-systemd-script: Script to enable systemd support on current Ubuntu WSL2 images Unsupported, no longer updated] (github.com)

Agent accessing host Windows in WSL2 - ZingLix Blog

ManageIQ - Easy Install With Docker

Docker container and win10 access the docker container in wsl_ Canger_ Blog - CSDN blog

Systemctl

WSL2 itself is run by Windows. Therefore, when you use the tree or ps command, you will see that the root process is not systemd, which will lead to failure to start the daemon of Linux system services. When we execute the systemctl command, it will show that our init system (PID 1) is not systemd, but / init provided by Microsoft.

$ systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
$ ps u -q 1
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0    908   592 ?        Sl   11:27   0:00 /init

Here, a script is used to solve the problem, which is used to enable the script supported by systemd on the current Ubuntu WSL2 image in the Windows store. This script is not supported and will no longer be maintained.

git needs to be installed:

sudo apt install git

git and run the script:

git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
# Enter your password and wait until the script has finished

After testing, it can be found that the PID1 process has changed from init to systemd:

$ ps u -q 1
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0  26724 12236 ?        Ss   01:08   0:00 /lib/systemd/systemd --unit=basic.target

Agent accessing host Windows in WSL2

This part is reprinted Agent accessing host Windows in WSL2 - ZingLix Blog

Get host ip:

cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'

Get WSL2's own ip:

hostname -I | awk '{print $1}'

Create a new proxy file under ~ SH, this code first obtains the ip address of the host and the ip address of WSL2 respectively, manually writes the port of the external agent to the constant port, and combines the host ip and the proxy port into a constant PROXY_HTTP, write set separately_ proxy(),unset_proxy() and test_ The three functions of setting() are executed according to the passed parameters:

#!/bin/sh
hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
wslip=$(hostname -I | awk '{print $1}')
port=<PORT>

PROXY_HTTP="http://${hostip}:${port}"

set_proxy(){
    export http_proxy="${PROXY_HTTP}"
    export HTTP_PROXY="${PROXY_HTTP}"

    export https_proxy="${PROXY_HTTP}"
    export HTTPS_proxy="${PROXY_HTTP}"

    export ALL_PROXY="${PROXY_SOCKS5}"
    export all_proxy=${PROXY_SOCKS5}
}

unset_proxy(){
    unset http_proxy
    unset HTTP_PROXY
    unset https_proxy
    unset HTTPS_PROXY
    unset ALL_PROXY
    unset all_proxy
}

test_setting(){
    echo "Host ip:" ${hostip}
    echo "WSL ip:" ${wslip}
    echo "Current proxy:" $https_proxy
}

if [ "$1" = "set" ]
then
    set_proxy

elif [ "$1" = "unset" ]
then
    unset_proxy

elif [ "$1" = "test" ]
then
    test_setting
else
    echo "Unsupported arguments."
fi

In line 4, replace the < port > with the port of your host agent. Here, Clash is used, and the port number is 7890:

At ~ / Add the following two sentences to bashrc, and change the path inside to the path where the script is placed:

alias proxy="source /path/to/proxy.sh"
. /path/to/proxy.sh set

My directory is / home/shark:

shark@LAPTOP-NJ5APBFE:~$ pwd
/home/shark

So add:

alias proxy="source /home/shark/proxy.sh"
. /home/shark/proxy.sh set

In this way, three commands proxy set, proxy unset and proxy test can be used in any path to set, delete and test proxy, for example:

$ proxy test
Host ip: 172.22.80.1
WSL ip: 172.22.80.169
Current proxy: http://172.22.80.1:7890

Running ManageIQ using Docker

Use the image provided by the ManageIQ project on the Docker Hub to test the ManageIQ running in the Docker container.

ManageIQ - Easy Install With Docker

Start docker:

sudo systemctl start docker

Step 1: official image:

docker pull manageiq/manageiq:lasker-1

There is a problem with the image provided here. Because the image cannot be found on the Docker Hub, replace it with

docker pull manageiq/manageiq:latest-lasker

Step 2: run container:

docker run -d -p 8443:443 manageiq/manageiq:latest-lasker

See if you run normally:

$ docker ps
CONTAINER ID   IMAGE                             COMMAND                  CREATED         STATUS         PORTS
                                     NAMES
c564bf9ffae8   manageiq/manageiq:latest-lasker   "/usr/bin/dumb-init ..."   4 seconds ago   Up 3 seconds   3000/tcp, 0.0.0.0:8443->443/tcp, :::8443->443/tcp   eager_joliot

However, at this time, it can only be accessed from within docker, not on the windows host, so port mapping is required.

The Docker port is mapped to the host

The currently running container and port mapping through docker container ls:

$ docker container ls
CONTAINER ID   IMAGE                             COMMAND                  CREATED          STATUS          PORTS                                               NAMES
c564bf9ffae8   manageiq/manageiq:latest-lasker   "/usr/bin/dumb-init ..."   50 minutes ago   Up 50 minutes   3000/tcp, 0.0.0.0:8443->443/tcp, :::8443->443/tcp   eager_joliot

At this time, you can only access port 8443 of the container in WSL2. You can view the Docker ip through ifconfig, but you can't access it directly on the win10 browser, so you need to establish a mapping. Open powershell as administrator:

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=8443 connectaddress=<wsl Medium linux of eth0 of ip> connectport=<wsl in linux Mapped port>

For example, I mapped port 8443 in the ubuntu of WSL2 to port 443 of the container, so I need to fill in port 8443, and then use the proxy configured above to check the ip address of WSL2:

$ proxy test
Host ip: 172.22.80.1
WSL ip: 172.22.80.169
Current proxy: http://172.22.80.1:7890

WSL IP found: 172.22.80.169:

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=8443 connectaddress=172.22.80.169 connectport=8443

After mapping, you can view:

netsh interface portproxy show all

Listen ipv4:                 connection to ipv4:

address            port        address            port
--------------- ----------  --------------- ----------
0.0.0.0         8443        172.22.80.169   8443

You can now access port 443 of the container (port 8443 of WSL2) using the native port 8443.

If you need to delete, you can use the delete command:

netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=8443

Visit ManageIQ and note that https: / /:

Default account password:

  1. Login: admin
  2. Password: smartvm

Keywords: Linux Docker Ubuntu Container

Added by jarriola on Mon, 17 Jan 2022 13:29:47 +0200