Docker and nodemcu-build. Excited but unable to run it - windows

I tried to install docker image today to build my firmware for esp6288 with http server and it seems that I failed miserably.
Install docker toolbox.
Run "C:\Program Files\Git\bin\bash.exe" --login -i "C:\Program Files\Docker Toolbox\start.sh" aka "Docker Quickstart Terminal" shortcut
See:
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
docker is configured to use the default machine with IP 192.168.99.100
For help getting started, check out the docs at https://docs.docker.com
Start interactive shell
Jaroslaw#lpatop MINGW64 ~
$
Run "C:\Program Files\Docker Toolbox\kitematic\Kitematic.exe" aka Kitematic (Alpha)
Search nodemcu-build by marcelstoer
Click Create...
After download, run.
See container logs:
fatal: Not a git repository (or any of the parent directories): .git
cp: cannot stat 'tools/esp-open-sdk.tar.gz': No such file or directory
Proceed according to https://hub.docker.com/r/marcelstoer/nodemcu-build/:
Open cmd:
Go to C:\Users\Jaroslaw (cmd already opens up in that dir)
Run git clone https://github.com/nodemcu/nodemcu-firmware.git
See, folder is there.
Go in to that folder.
Run:
docker run --rm -ti -v //c/Users/Jaroslaw/nodemcu-firmware:/opt/nodemcu-firmware marcelstoer/nodemcu-build
See output:
docker: An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/containers/create: open //./pipe/docker_engine: The system cannot find the file specified..
See 'docker run --help'.
Can you tell me what should I do to make this work? I'm very excited to start building my universal IoT unit for my home purposes with http server onboard.

The default NodeMCU firmware can be used to create an HTTP server. You don't need to build the firmware from source again to do that.
Download precompiled NodeMCU firmware from here. (Note that it's not the latest version! Latest no longer ships with precompiled binaries since there are lots of configurations to choose from. Once you get started, it is recommended to build the latest firmware as mentioned in bold below since this old version is reported to be buggy.)
Download ESPFlasher from here and flash the firmware onto the chip. (This is the only flasher that worked for mee).
Just flash the firmware onto the chip and download ESPlorer IDE. The IDE allows you to write Lua scripts onto the device, which can also be used to create an HTTP server.
See this page for an example of a web server emulated on ESP8266. This example works out of the box if you are using the precompiled firmware from (1). If you are building your own firmware from the latest source, it is recommended to use these scripts which are maintained.
Hope this helps.
To build your own firmware, simply do this:
If you ever feel like compiling your own firmware from the latest source, you can always head over to http://nodemcu-build.com and compile a custom firmware online, and get it emailed to you.

Related

How to install Golang on chrome os

I tried the method from https://go.dev/doc/install and I keep getting "-bash: go: command not found".
I tried https://gist.github.com/conoro/4fca191fad018b6e47922a21fab499ca but I dont know what command to run when I get to the "Use sftp or scp on the ARM64 device to get the tar.gz file" stage. Any help???
You don't need to compile from source in Developer mode, you can just use the Chromebrew-provided version.
If your Chromebook is relatively new, you can enable the Linux VM now built into ChromeOS to install Go without developer mode. Follow the steps from the following Google Support article to enable this feature- https://support.google.com/chromebook/answer/9145439. This has been tested on a Samsung Chromebook Plus on version 71.0.3578.127. If this feature is not available for you, you will need to enable Developer Mode.
This tutorial will show you how to install, build, and run Go on Chrome OS.
Please note this has only been tested on a 64GB LTE Pixel, however it should work on other Chromebooks. Note that enabling developer mode reduces the security guarantees offered by Chrome OS.
Install Go
First download the latest version of Go for Linux from the Go Downloads page.
After that, open a shell by hitting (CTRL+ALT+T) and typing in shell then hit enter. Then extract it using the following command (when replacing < Go Linux package > with the name of the file you downloaded):
sudo tar xpvf ~/Downloads/< Go Linux package > -C /usr/local
Go should now be installed you can test this by typing /usr/local/go/bin/go. If it installed correctly, you should see the Go help prompt. Go is now installed.
Create a Workspace
To keep this simple just create a folder called /usr/local/go/work. Also, create a folder called src inside /usr/local/go/work/.
Set PATH
Add the following to ~/.bashrc:
export GOPATH="/usr/local/go/work"
export PATH="${PATH}:/usr/local/go/bin:${GOPATH}/bin"
This will allow you to run your Go programs in your shell.
Test if it worked
First create a folder inside of your /usr/local/go/src folder. After that create a file in your folder called hello.go with the following in it:
package main
import "fmt"
func main() {
fmt.Println("Hello, Chrome OS!")
}
Now, run go install hello. Then, run ${GOPATH}/bin/hello (or just hello if you setup your GOPATH above) and you should see Hello, Chrome OS!.
Collected from : https://github.com/golang/go/wiki/ChromeOS
If you want to download Go on a Chromebook in Dev Mode, without installing Linux follow these steps:
Enable Dev mode, in case you have not already.
Download the latest version of Go for Linux (https://go.dev/dl/)
IN YOUR TERMINAL
Type Shell
mkdir ~/Coding
tar -xzf ~/Downloads/ADD YOUR VERSION HERE -C ~/Coding/
echo "sudo mount -i -o remount,exec /home/chronos/user/" >> ~/.bash_profile
echo "sudo mount -i -o remount,exec /tmp/" >> ~/.bash_profile
SET ENV VARIABLES
export GOROOT=~/CS/go *Where you extracted Go*
export GOPATH=~/Downloads/go *Where you wanna keep your Go projects*
PATH=$PATH:$GOROOT/bin:$GOPATH/bin *This adds everything to PATH*
To make sure everything works restart your Terminal and type go version you should see the version you installed

Issue running chrome driver in docker image

I have written some scripts to extract some data from website using selenium. Although my code runs well outside of docker container, it fails when I run it after building an image. I searched through the google and looked over the internet to find the similar issue but could not find something similar. Here I have posted my docker file,
# syntax=docker/dockerfile:1
FROM python:latest
WORKDIR /Users/ufomammut/Documents/eplrestapi
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN curl https://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip -O
RUN unzip chromedriver_linux64.zip
COPY . .
CMD [ "python3", "epl.py"]
The error message I receive when I run the docker image that I built,
Traceback (most recent call last):
File "/Users/ufomammut/Documents/eplrestapi/epl.py", line 172, in <module>
browser = webdriver.Chrome("./chromedriver",options = chr_options)
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service ./chromedriver unexpectedly exited. Status code was: 255
In my code I have provided the path to the chromedriver as follows:
browser = webdriver.Chrome("./chromedriver",options = chr_options)
Right now I used linux arm64 python base image and was able to curl and unzip the chromedriver as reflected in my dockerfile above.I am no longer receiving the format error but I am receiving this error message as I posted above where it says the chromedriver unexpectedly exited.
You appear to have copied a chromedriver binary built for MacOS into a Debian machine.
Based on how you've tagged this question with macos and the image python:3.9.5-slim-buster you are using is amd64 based on Debian.
I suggest you continue persisting with trying to curl the Linux 64 bit chromedriver into your machine via your Dockerfile.
To test it in your host OS you can simply change your current chromedriver binary to chromedriver.bakup. Download the linux version to chromedriver and rebuild your docker machine and it will copy the linux version into the new image.
Looks like you have been using chromedriver binary for MacOS instead of its linux version.
To make it a 'workable' piece of code, you can try linux binary and perform volume mapping when you try to run your docker image. Use the linux binary for chromedriver and put it in a seperate directory in your system which needs to be mapped. And when you run your image try using:
docker run -v <directory_path_to_chromedriver>:<docker_image_directory_path> <image>
Your final piece of code will be updated with your new binary file path.
browser = webdriver.Chrome("<docker_image_directory_path>/chromedriver",options = chr_options)
But for permanent fix, curl and unzip the linux binary while you build the docker image.
After going through the comments, I believe you're a little confused with Docker containers and how they interact with your system.
A Docker container runs it's own independent, isolated and optimised version of an operating system determined by the FROM layer, and leverages your system's kernel.
Now, you must use Chrome Webdriver binaries compatible with linux arm64, rightly pointed out by #Shubham and #lgflorentino. It seems that you've already done so.
Your next steps should be to check permissions on the Chrome Webdriver executables, and make sure that your container has setup all the environment paths and variables correctly.
You can do so by entering your container with the command docker exec -it /bin/bash or /bin/sh and then manually execute your bins. This will give you a clearer picture.
Check your environment variables as well!
Also, an improved Dockerfile with reduced number of layers can be as well.
FROM python:latest
#Use a deterministic Python image, mention a version instead of 'latest'
WORKDIR /Users/ufomammut/Documents/eplrestapi
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt && \
curl https://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip -O && \
unzip chromedriver_linux64.zip
COPY . .
#Try adding an ENV layer to make sure your paths are setup properly. (After debugging your container)
CMD [ "python3", "epl.py"]
Since you have tagged with macOs and ARM64, I believe that your development machine has Apple Silicon or M1 chip. The docker engine on the Apple Silicon machine will by default pulls ARM64 based images and your chrome driver is of linux64. This means your chrome driver can't run inside the host.
You can either use arm64 chrome driver or build docker image form amd64 platform.
docker build -t your-username/multiarch-example:manifest-amd64 --build-arg ARCH=amd64
Try adding the --platform=linux/amd64 to the FROM statement. I used this for Debian:
FROM --platform=linux/amd64 python:3.9

Docker Image built on Mac OSX won't run on AWS EC2 instance

Image built on Mac OSX with M1 processor, deployed to an EC2 instance. But when scripts are run it yields the error:
standard_init_linux.go:219: exec user process caused: exec format error
Elsewhere on Stackoverflow, this is explained as a mismatch of OS architecture. Sure enough running "uname -m" on EC2 instance shows it to be x86_64, and "docker image inspect" shows the container to have architecture arm64.
Here's what I don't understand. "uname -m" on my Mac shows that to be x86_64 too. So how does the container inherit a different architecture?
More significantly, how do I build an image on my Mac that I can run on EC2?
Docker file is simply
FROM python
WORKDIR /
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY src /src
with src containing, currently, some simple python scripts, executed thus:
docker run container/name python test.py
This works fine on my Mac, but gives the error above when executed on AWS.
OK. Here's what's happening. My Mac has the new M1 chip and I'm running the Tech Preview version of Docker Desktop. Under the hood the chip has the arm64 architecture, but interrogating it through iTerm and VSCode it claims to be x86_64 instead, hence my confusion when I posted the question. This is probably because both those apps are being quietly run through an Intel simulator behind the scenes and that's what's responding to the uname command.
However, because the processor is really arm64, that's the base architecture when I pull Python images from Docker (I tried lots of different flavours nd version of Python - all with the same results).
To force use of an amd64 AWS-compatible image I changed the first line of the Dockerfile to:
FROM --platform=linux/x86-64 python.
When containers from this image are run on the Mac that causes a warning
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
but it's just that, a warning, and the script runs (presumably by redirecting back through the Intel simulator. The scripts now run without problem (or warning) on the EC2 instance.
I'm not sure why you're getting this error, but there is a nice way to get around it if you'd like and if you don't mind your code and images being public. I'm guessing that this is just home-stuff anyway, so it might not be too bad.
Put your code in github.
Configure a repository on
hub.docker.com for your image and configure automatic builds from
github
ssh onto your ec2 instance and pull your image directly
from docker hub
An alternative is to start with step 1, then log into your ec2 using ssh and clone the repo on that machine. You can then build it directly on a real linux machine (your osx machine doesn't run Linux, which is an instant mismatch with docker). If you build it on the server you should be able to run it there with no problems.
Try to run with CMD ["lscpu"] or something related like cat /proc/cpuinfo in the container, compare architectures
Another thing: you might be pulling arm architecture of python image when building, and try to run it on x86_64 (EC2)
In addition to what has been shared above, you could also Build a multi-arch image with Buildx.
Basically, The recent Docker versions come with a CLI command called buildx. You can use the buildx command on Docker Desktop for Mac and Windows to build multi-arch images, link them together with a manifest file, and push them all to a registry using a single command.
Here is what works for me:
Create a new builder which gives access to the new
multi-architecture features.
docker buildx create --name mybuilder --use
Build the Dockerfile with buildx, passing the list of architectures to build for:
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t username/demo:latest --push .
=> pushing layers 2.7s
=> pushing manifest for docker.io/username/demo:latest 2.2
Where, username is a valid Docker username.
Notes:
The --platform flag informs buildx to generate Linux images for AMD 64-bit, Arm 64-bit, and Armv7 architectures.
The --push flag generates a multi-arch manifest and pushes all the images to Docker Hub.
To inspect the image use the below command
docker buildx imagetools inspect username/demo:latest

How to debug a .NET Core application running in a Linux Docker container from Visual Studio

I have my own hand written Dockerfile/docker-compose files. I start containers from command line. Now I want to attach Visual Studio 2017 (not Visual Studio Code) to my application inside a Docker (Linux-based) container. It seems it should a pretty easy task, but I can't find any information on how to do this.
I read through the guide Off-road Debugging of .NET Core on Linux or OS X from Visual Studio carefully. At first it looked like what I needed - a description on how to remotely debug a .NET Core application running in Linux. But it only tells a part of the story - how to debug via SSH. And just mentions Docker, but it says nothing to how to remotely debug an application inside Docker.
I guess there shouldn't be much specific of Docker here, it's just running vsdbg inside Docker and attaching here. But obviously it's a very common dev use case and it's weird that there's no good information on this.
Surely, there are VS Tools for Docker using which we can easily do debugging of an application inside a Docker container. But for me, VS Tools for Docker are just terrible. Yes, they work seamlessly at first. But it is absolute unclear what is going on under the hood.
It seems that we just can look up what VS Tools for Docker do and try to reproduce that. But it's not very obvious. It adds an additional "debug" YAML file to docker-compose (docker-compose.vs.debug.g.yml) which should do the debugging magic. I tried to add that YAML content to my hand-written docker-compose, run Dockers, but how can I attach Visual Studio?
I get the IP address of my container, tried to find a remote debugger on that IP address and 4022 that Visual Studio can't see anything. Also it's suspicious that file debug.yaml created by Tools for Docker has nothing about exposing the 4022 port as it could be expected.
P.S.: I found a good guide but on Windows containers
How about this:
If your service is based off of the microsoft/dotnet Docker image, create a new dockerfile based on the same image, and install the debugger, ssh and unzip.
FROM microsoft/dotnet
RUN apt-get update && apt-get -y install openssh-server unzip
RUN mkdir /var/run/sshd && chmod 0755 /var/run/sshd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin without-password/g' /etc/ssh/sshd_config
RUN sed -i 's/#StrictModes yes/StrictModes no/g' /etc/ssh/sshd_config
RUN service ssh restart
RUN mkdir /root/.vs-debugger && chmod 0755 /root/.vs-debugger
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v vs2017u1 -l /root/.vs-debugger/
EXPOSE 22
Build and push this to your registry.
docker build -t myregistry/dotnetdebugger .
docker push myregistry/dotnetdebugger
Next ensure that your service's build is outputting the PDB files as portable PDB files -
Offroad Debugging of .NET Core on Linux and OS X from Visual Studio
And ensure that the PDB files are included with the DLL files when you build your service's Docker image.
Then when your container is running and you decide that you need to debug it, you can attach the debugger container as a side car container to the service:
docker run -d -p 10222:22 --pid container:<container name> - myregistry/dotnetdebugger
Then in Visual Studio, go to menu Tools → Options → Crossplatform → Connection Manager - and add a new connection. Specify the IP address or hostname of the container, 10222 as the port (the one in the docker run command), and root as the user with no password.
As of May 2018, if you are using Visual Studio, you can use their official support.
You just need to have installed Docker and add the support for Docker projects menu Project → Docker support.
This creates a new project with a Docker compose and a dockerfile to your project, and then Visual Studio links this and allows debugging!

How to run a library in docker - confusion

I am trying to use microsoft's cntk library on a mac; for this purpose I am using Docker. I am not an expert in all this, though, so I am having a hard time figuring out how to make it work.
From my understanding, Docker provides a way to run an app in a virtualized environment, without having to virtualize the entire operating system. So you download (or create) images, and you run them in "containers".
Alright, so I have followed the required steps to make the cntk library work on Docker; and if I list the images, I find
$: docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
microsoft/cntk latest c2c192036e19 7 days ago 5.92 GB
ubuntu 14.04 7c09e61e9035 5 weeks ago 188 MB
hello-world latest 48b5124b2768 2 months ago 1.84 kB
At this point I want to run of the tutorials that are in the cntk repository. I have downloaded the master branch of the cntk repository on my desktop and try to run one of the examples in the "Tutorial" folder, but I get the following error:
terminal~ username$ docker run -w /Users/username/Desktop/CNTK-master/Tutorials microsoft/cntk configFile=lr_bs.cntk
container_linux.go:247: starting container process caused "exec: \"configFile=lr_bs.cntk\": executable file not found in $PATH"
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"configFile=lr_bs.cntk\": executable file not found in $PATH".
ERRO[0001] error getting events from daemon: net/http: request canceled
terminal~ username$
Essentially I call docker run with the -w flag to inform him of where the files are, but it does not work. I tried searching online but it's not clear to me how to solve the issue. Should I create a new image? Should I call the docker run command with different parameters?
The -w flag sets the working directory, which is just the default directory inside the container. Your directory is on the host, so it won't work here. Instead you need to use volumes to mount your directory on the host into the container. The final paragraph in the document you link has an example:
$ docker run --name cntk_container1 -ti -v /project1/data:/data -v /project1/config:/config cntk bash

Resources