Dockerize react-native dev environment & connect Android device to WSL2 - windows

I want to dockerize my react native development environment. Currently I have windows on my laptop, and I don't have the option to change that. I also have WSL2 installed and I started to build my dockerfile from this image
I also want to use my device, so I have to somehow connect the container (the docker runs actually in WSL2) with my android device. The WSL2 don't support USB devices (that are connected to the host windows system) currently so I was thinking about setting up a wireless adb connection on the local network but since my android is <11 I have to do some initial setup which requires me to connect adb over USB which is due to the reasons above, not possible... I don't want to use an USB server. Any ideas?

Assuming you have the whole dev-environment setup and working on linux/wsl, you can use socat to relay requests from wsl2 to adb on windows. You may have to deal with some firewall issues, but this works for me:
On Windows:
Run adb -a -P 5037 nodaemon server (credit to this redditor)
In another terminal, run adb devices to ensure your device is properly connected over usb.
On linux/wsl2:
Run socat -d -d TCP-LISTEN:5037,reuseaddr,fork TCP:$(cat /etc/resolv.conf | tail -n1 | cut -d " " -f 2):5037 (credit to this gist)
If you are developing for android with react-native and need to launch the metro bundler, you will need to open a port for the metro bundler on your windows firewall. I will assume you are using port 8081.
Run as administrator in powershell (Windows):
$WSL_CLIENT = bash.exe -c "ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'"
iex "netsh interface portproxy add v4tov4 listenport=8081 listenaddress=127.0.0.1 connectport=8081 connectaddress=$WSL_CLIENT"
You should now be able to deploy your project to andriod.
On linux/wsl2:
npx react-native start
npx react-native run-android
If this doesn't work, the credited sources for steps (1) and (3) provide similar methods for achieving this. If you make a docker image, please share it here!

Related

Acces Windows COM port from docker(linux container)

I need to have acces to windows com port(COM3) form docker linux contianer:
I tried like this:
docker run -d --name test_com_port -p 8090:80 --device=/dev/ttyACM14 --restart always test_com_port
docker run -d --name test_com_port -p 8090:80 –-device=COM3:/dev/ttyS2
--restart always test_com_port
docker run -d --name test_com_port -p 8090:80 –-device=//./COM3:/dev/ttyS2
--restart always test_com_port
but don't have any results. Also I visited microsoft tutorial but it is only for windows containers. Maybe some one have any solutions how to solve it?
hey there I was successfully able to map a windows serial device to a docker container, it was a long and tedious task but in the end I was successful. Any who has access to windows 10 with support for WSL 2 can follow these steps:
1.) Install WSL 2 with Ubuntu distro as it's easier to work with.
2.) On the windows host machine install this software called usbipd through command winget install usbipd for more information use this link
3.)Now we have to configure a few things in the Ubuntu distro so that the interfacing happens for that you will have to follow this link
4.)Once that is done you can now mount the device, before we start the mounting process make sure to plug-in the device to the windows host
5.)Before mounting you can check the list of available devices with usbipd wsl list. You will be able to see all the serial devices connected and now you can
interface or mount or attach using the command usbipd wsl attach --busid=<BUSID>
6.)Once the device is attached you can open the wsl Ububtu use the command lsusb to check all available serial devices which communicate over USB.
7.)Now the final step is to mount the device to docker container with command --device /dev/<available port>; ex doecker run -d --device=/dev/<available ports from liunx ubuntu distro> <container>

bluetooth in docker for windows host

My docker version is:
docker --version
Docker version 20.10.2, build 2291f61
My windows version is:
systeminfo
Nom du système d’exploitation: Microsoft Windows 10 Professionnel
Version du système: 10.0.17763 N/A version 17763
Type du système: x64-based PC
My Dockerfile is:
FROM ubuntu:21.04
RUN apt update
RUN apt-get install -y bluez bluetooth usbutils
When I run the following command, I start the 'bluetooth_in_docker' container:
docker build -t bluetooth_in_docker . & docker run --privileged --net=host -it bluetooth_in_docker bash
Inside the container when I run the following, I get an error:
hciconfig dev
Can't open HCI socket.: Address family not supported by protocol
I got it working on Windows from inside WSL2, but it takes a lot of steps.
Follow https://github.com/dorssel/usbipd-win/discussions/310 to get
your bluetooth working inside WSL2. Verify that you can scan for
bluetooth devices inside your WSL2 distro.
modify your dockerfile to install bluetooth as you did (bluez and usb-utils might not be needed)
Now there are 2 options. First option shares bluetooth with container. Second option gives container exclusive control.
Sharing bluetooth between the host and the container is possible by making a volume mount of /var/run/dbus and running it with --privileged:
docker run -v /var/run/dbus/:/var/run/dbus/:z --privileged {containerImage}
Make sure that the dbus and bluetooth services are working in your host when running the container this way.
Giving the container exclusive control: in WSL2 (the host), run a docker container according to https://stackoverflow.com/a/64126744/1114918
run sudo service bluetooth stop to make your bluetooth not "claimed" by the host (the linked answer uses killall, I think sudo service ... stop is cleaner)
use a sh script to start dbus and bluetooth inside the container
run the container using
docker run --rm --net=host --privileged myimage:mytag

Docker for Desktop error during connect: Post A connection attempt failed because the connected party did not properly

I have freshly installed Docker for Desktop Edge in Windows 10 Home and try to build an image using the docker build command. But unfortunately, it didn't work for me, and got the below error :
CMD - docker build -t heet1996/post:0.0.1 .
error during connect: Post https://192.168.99.100:2376/v1.40/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&session=na8ugnpn6d8gnxl3z8ppx4gap&shmsize=0&t=heet1996%2Fpost%3A0.0.1&target=&ulimits=null&version=1: dial tcp 192.168.99.100:2376: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Earlier I was using a docker toolbox so I had to remove all the environment variables related to the Docker in my User variables before installing Docker for Desktop. After a lot of search on GitHub issues, I am still not getting the solution.
This is what I found in my service.txt file (C:\ProgramData\DockerDesktop\service.txt)
[18:27:22.232][LoggingMessageHandler][Info ] [f9b6b957] <Server end> POST http://localhost/dns/refresh-hosts -> 204 NoContent (took 118ms)
I got this error when i un-installed the docker toolbox and installed the docker desktop.
System Configuration:
OS: Windows 10 Home
Version: 21H1
Steps I Followed:
Un-installed the docker desktop.
Removed the all dockers related environment variables from the user variables.
Navigation: This System-> Properties-> Advance System Settings-> Environment Variables-> User Variables.
Re-installed the docker desktop and it's started working properly.
Try to run it on Docker CLI instead of CMD
Open Powershell as Administrator and run the below commands
cd "C:\Program Files\Docker\Docker"
./DockerCli.exe -SwitchDaemon
Docker for windows must have:
[✓] Updated Windows 10 version >=2004
[✓] WSL 2 and Default Distro (i.e ubuntu)
The steps are well documented here. These are what to do after the installation:
To confirm ubuntu's installation, open C:/Windows/System32/bash.exe aka bash.
To test if docker is properly installed, run docker version on bash. This should print the docker client and server engine.
After successfully tested and confirmed the installations, try entering your command
$ docker build -t heet1996/post:0.0.1 .
here we are talking about using Docker with PowerShell and not with WSL. And also following the addition of variables in the environment variables of Windows.
Configuration when this response was made:
Windows 10 Pro 20H2 (Build 19042.867)
Docker 20.10.5
Powershell 5.1.19041.610
I also had to configure docker in a dirty way too much, after several hours of research and a comparison of installation on a clean Windows 10 I understood where my error was.
In addition to the user environment variable also make sure that you do not have DOCKER variables in the Windows system environment variables either.
Here is where my error was, I think it was due to the installation of the Docker module
I had the DOCKER_HOST variable in my system variable environment, so i deleted it.
If you want to check all your environment variables with Powershell:
[System.Environment]::GetEnvironmentVariables()
If you really want a Docker fresh installation on Windows, you need to delete the following folders:
C:\ProgramData\Docker
C:\Program Files\Docker\Docker
$HOME\AppData\Local\Docker
$HOME\AppData\Roaming\Docker
$HOME\AppData\Roaming\Docker Desktop
$HOME\.docker
my error, therefore, produced this error:
ERROR ==> error during connect: Get http://docker.artofshell:2376/v1.24/version: dial tcp: lookup docker.artofshell: no such host
After a complete uninstall of all docker (Via chocolatey, official docker ...) and by properly installing Docker from the official executable here everything is back to normal
Then if you want to use docker via Powershell you have to change the configuration of DockerCLI as you can see on many answers
Conclusion
It is possible to use docker with Powershell you must check if the
server daemon is used by Windows/amd64, you can modify the daemon with this command cd "C:\Program Files\Docker\Docker"; .\DockerCli.exe -SwitchDeamon
You can check the configuration of the daemon with the following command: docker version
You must remove all traces of old Docker installations if you had any
You must delete the environment variables from the old installation or from the docker toolbox
You must also activate the experimental features: information here

Cannot find Jupyter Notebook server on port 8888 (Windows 10)

I'm trying to run a Docker container as a Jupyter Notebook on Windows 10. As shown in the screen grab, the notebook appears to be running on localhost:8888, but my browsers (Chrome and Edge) return a 'connection refused' error. I've disabled my firewall (temporarily), but that didn't help. Also, netstat does not list the port as being in use. Any idea what's going on?
Try the following:
docker run -p 8888:8888 -it simonwalkersamuel/bloch_tf:latest
-p 8888:8888 will map container port 8888 to host port 8888.
TLDR make sure you mapped the ports using -p 8888:8888. If didn't work, try 192.168.99.100:8888 instead of localhost:8888.
Situation:
I had a slightly different problem: Although I mapped the ports using -p 8888:8888, I still see the connection error when I try to reach localhost:8888 in all browsers. The firewall is checked and seems OK. It was very confusing because exactly same docker image works on my other Win 10 laptop at work.
Solution:
I have two slightly different Win 10 on my laptops. The one that has connection difficulty runs a Win 10 Home whereas the other one has a Win 10 Professional. This means, the problematic laptop only runs Docker Tools not the conventional Docker CE. Therefore, it maps communicates with the OS using 192.168.99.100 IP not the usual 127.0.0.1 or localhost. So, instead of localhost:8888 just used 192.168.99.100:8888 and it worked.
Confession!
I usually use my work laptop for running Jupyter on docker. Therefore, I did not pay enough attention to the welcome message of Docker Quickstart Terminal which clearly says docker is configured to use the default machine with IP 192.168.99.100. Hopefully, this post helps other too busy (aka careless!) people like me!
Since both laptops have very similar apps installed, I doubt anything rather than the Docker app itself causes the difference in IP addresses.
Try the following commands:
run these two command
pip install --upgrade pip
pip install --upgrade jupyter

Set up rancher host on windows

I installed rancher server on my mac osx.
Then I have a windows computer where i want to deploy my host.
I ran the command line which looks like so on my window computer:
docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.0.1 http://192.168.99.100:8080/v1/scripts/E915A1D0B7E952F73D4E:1466539200000:MoUKnbVNKKFV8Q4CDbDMI2DvPQ
But the host doest not appear in the hosts lists.
Is there any configuration I have to set up on the windows machine like opening a port or whatever ?
Thanks
Windows support is something we are working on, but not supported yet. The agent needs a fair bit of rework to work on Windows.

Resources