How to access USB ports from Docker Container on Mac OS - macos

I have created a Docker container for building and testing my Flutter apps. I want to connect my mobile device to the USB port of my Macbook and run Flutter apps directly on the device from the Docker container. But, I am unable to access the USB ports from the container and receiving this error.
I am using Remote Development extension inside my VS Code for running the container.
The devcontainer.json file is attached below:
{
"name": "flutter_docker",
"context": "..",
"dockerFile": "../Dockerfile",
"remoteUser": "developer",
"mounts": [
"source=/dev/bus/usb,target=/dev/bus/usb,type=bind"
],
"settings": {
"terminal.integrated.shell.linux": null
},
"runArgs": ["--privileged"],
"extensions": ["dart-code.flutter"],
"workspaceMount": "source=${localWorkspaceFolder}/workspace,target=/home/developer/workspace,type=bind,consistency=delegated",
"workspaceFolder": "/home/developer/workspace"
}
Whenever I remove the mounts from the json file, it runs fine without any error.
Removing this line:
"mounts": [
"source=/dev/bus/usb,target=/dev/bus/usb,type=bind"
],
Dockerfile:
FROM ubuntu:18.04
# Prerequisites
RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget
# Setup new user
RUN useradd -ms /bin/bash developer
USER developer
WORKDIR /home/developer
# Prepare Android directories and system variables
RUN mkdir -p Android/Sdk
ENV ANDROID_SDK_ROOT /home/developer/Android/Sdk
RUN mkdir -p .android && touch .android/repositories.cfg
# Setup Android SDK
RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN unzip sdk-tools.zip && rm sdk-tools.zip
RUN mv tools Android/Sdk/tools
RUN cd Android/Sdk/tools/bin && yes | ./sdkmanager --licenses
RUN cd Android/Sdk/tools/bin && ./sdkmanager "build-tools;29.0.2" "patcher;v4" "platform-tools" "platforms;android-29" "sources;android-29"
# Download Flutter SDK
RUN git clone https://github.com/flutter/flutter.git
ENV PATH "$PATH:/home/developer/flutter/bin"
# Run basic check to download Dark SDK
RUN flutter doctor

Currently, there is an open bug in GitHub about USB Passthrough. Also it was mentioned in the Docker FAQs that it is not possible to pass through a USB device:
Unfortunately, it is not possible to pass through a USB device (or a
serial port) to a container as it requires support at the hypervisor
level.

Related

How to run Dockerfile at Silicon Mac M1 from Intel Mac

I'm not a native speaker of English, but I want to ask a question on Stack Overflow.
and I am a beginner at Docker.
I am trying to set up the development environment at Silicon Mac M1 from Intel mac.
#!/bin/sh
set -e
. ./env.list
# Build Docker image
# docker pull store/ibmcorp/db2_developer_c:11.1.4.4-x86_64
docker build -t ${REPOSITORY}:${TAG} .
# DOCKERFILE
FROM store/ibmcorp/db2_developer_c:11.1.4.4-x86_64
RUN yum -y update && yum clean all
RUN curl ftp://ftp.pbone.net/mirror/vault.centos.org/7.8.2003/os/x86_64/Packages/glibc-common-2.17-307.el7.1.x86_64.rpm > /tmp/glibc-common.rpm
RUN rm -f /etc/localtime
RUN mkdir /var/custom
and I got errors like below
Step 2/30 : RUN yum -y update && yum clean all
---> [Warning] The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
I already add --platform linux/amd64 another docker run command
#!/bin/bash
. ./env.list
docker rm -f api-db
docker run --name api-db -h db2server --restart=always --detach --privileged=true -p 50000:50000 -p 55000:55000 --platform linux/amd64 --env-file env.list sample-app:v1.0
what should I do for a dockerfile?
Thank you so much for reading.
Have a good day! :)
Apple M1 is arm64v8 instruction set processor, so you can not run amd64 (X86_64) on it without emulation. In general, Docker has the ability to emulate other architectures if the emulation based on bitfmt is set up (and on maxOS with intel CPU it's already set-up), however the emulation for amd64 on M1 is not stable yet. This means that for some period of time you will be restricted to 'arm64' images.
To fetch the proper image for you architecture during the build you need to add the following.
FROM --platform linux/arm64 <image name>
You need to check if there are images for db2 development environment for arm by doing
docker pull --platform linux/arm64 store/ibmcorp/db2_developer_c

Can ClearML (formerly Trains) work a local server?

I am trying to start my way with ClearML (formerly known as Trains).
I see on the documentation that I need to have server running, either on the ClearML platform itself, or on a remote machine using AWS etc.
I would really like to bypass this restriction and run experiments on my local machine, not connecting to any remote destination.
According to this I can install the trains-server on any remote machine, so in theory I should also be able to install it on my local machine, but it still requires me to have Kubernetes or Docker, but I am not using any of them.
Anyone had any luck using ClearML (or Trains, I think it's still quite the same API and all) on a local server?
My OS is Ubuntu 18.04.
Disclaimer: I'm a member of the ClearML team (formerly Trains)
I would really like to bypass this restriction and run experiments on my local machine, not connecting to any remote destination.
A few options:
The Clearml Free trier offers free hosting for your experiments, these experiment are only accessible to you, unless you specifically want to share them among your colleagues. This is probably the easiest way to get started.
Install the ClearML-Server basically all you need is docker installed and you should be fine. There are full instructions here , this is the summary:
echo "vm.max_map_count=262144" > /tmp/99-trains.conf
sudo mv /tmp/99-trains.conf /etc/sysctl.d/99-trains.conf
sudo sysctl -w vm.max_map_count=262144
sudo service docker restart
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo mkdir -p /opt/trains/data/elastic_7
sudo mkdir -p /opt/trains/data/mongo/db
sudo mkdir -p /opt/trains/data/mongo/configdb
sudo mkdir -p /opt/trains/data/redis
sudo mkdir -p /opt/trains/logs
sudo mkdir -p /opt/trains/config
sudo mkdir -p /opt/trains/data/fileserver
sudo curl https://raw.githubusercontent.com/allegroai/trains-server/master/docker-compose.yml -o /opt/trains/docker-compose.yml
docker-compose -f /opt/trains/docker-compose.yml up -d
ClearML also supports full offline mode (i.e. no outside connection is made). Once your experiment completes, you can manually import the run to your server (either self hosted or free tier server)
from clearml import Task
Task.set_offline(True)
task = Task.init(project_name='examples', task_name='offline mode experiment')
When the process ends you will get a link to a zip file containing the output of the entire offline session:
ClearML Task: Offline session stored in /home/user/.clearml/cache/offline/offline-2d061bb57d9e408a9420c4fe81e26ad0.zip
Later you can import the session with:
from clearml import Task
Task.import_offline_session('/home/user/.clearml/cache/offline/offline-2d061bb57d9e408a9420c4fe81e26ad0.zip')

Cannot run JavaFX app on docker for more than a few minutes

I developed an application used as a communication service for a separate web app. I had 0 issues "dockerizing" the web app but the service is proving to be a nightmare. It is based on JavaFX and there is a property that can be set by the user in the config file that makes it so the app does not initialize any windows, menus, containers, etc. This "headless" mode (not sure that is truly headless...) effectively turns the service app into a background service. Let me also preface this by saying that the app works absolutely flawlessly when run on my windows 10 machine and that i have deployed it on several other machines (all non-dockerized) with no issues.
Here is the dockerfile i came up with :
FROM openjdk:13.0.1-slim
RUN apt-get update && apt-get install libgtk-3-0 libglu1-mesa -y && apt-get update
VOLUME /tmp
ADD Some_Service-0.0.1-SNAPSHOT.jar Some_Service-0.0.1-SNAPSHOT.jar
ADD lib lib
ADD config.properties config.properties
ENTRYPOINT ["java", "--module-path", "lib/javafx-sdk-13", "-jar", "Some_Service-0.0.1-SNAPSHOT.jar"]
I then use this command to build the container :
docker run -t --name Some_Service -e DISPLAY=192.168.1.71:0.0 -e SERVICE_HOME= --link mySQLMD:mysql some_service
Assuming VcXsrv is running on my PC, the app start correctly, although it does give these warnings when first starting :
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Prism-ES2 Error : GL_VERSION (major.minor) = 1.4
The issue is that it only works for like 2 minutes. Eventually the container comes up with this error and crashes :
Gdk-Message: 15:28:54.770: java: Fatal IO error 11 (Resource temporarily unavailable) on X server 192.168.1.71:0.0.
I understand the initial messages are due to the container having no NVidia driver but the fallback to the software pipeline seems to work fine. Honestly I have no idea what the fatal IO error could be caused by. I have tried on different hosts running docker and the same issue happens.
Any idea how to fix this? Even better, any idea how to make a JavaFX app TRULY headless and not even require any of this stuff to be initialized? When running headless, i use Tasks and such which are part of JavaFX so I can't just not use it...
Install xvfb in your container this create a virtual screen.
change to Docker file:
FROM openjdk:13.0.1-slim
RUN apt-get update && apt-get install libgtk-3-0 libglu1-mesa xvfb -y &&
apt-get update
VOLUME /tmp
ADD Some_Service-0.0.1-SNAPSHOT.jar Some_Service-0.0.1-SNAPSHOT.jar
ADD lib lib
ADD config.properties config.properties
apt-get install xvfb
ENV DISPLAY=:99
ADD run.sh /run.sh
RUN chmod a+x /run.sh
CMD /run.sh
Add new bash Script in your project folder and name it "run.sh"
run.sh:
#!/bin/bash
#remove old
rm /tmp/.X99-lock #needed when docker container is restarted
Xvfb :99 -screen 0 640x480x8 -nolisten tcp &
java --module-path lib/javafx-sdk-13 -jar Some_Service-0.0.1-SNAPSHOT.jar
Dont forget to remove -e DISPLAY=192.168.1.71:0.0 from your docker run command

Nginx failed to build on a Ubuntu Droplet (Digital Ocean / Laradock)

I'm trying to upload a laradock environment on an Ubuntu droplet in DigitalOcean, however, it returns me a failure while starting nginx.
adduser: group 'www-data' in use
ERROR: Service 'nginx' failed to build: The command '/ bin / sh -c apk update && apk upgrade && apk add --no-cache openssl && apk add --no-cache bash && adduser -D -H -u 1000 -s / bin / bash www-data 'returned a non-zero code: 1
See the image below:
What can I do to resolve this problem?
I reinstalled version 19 of Ubuntu and did not succeed either.
On my Mac OS X it starts normally.
I also tried reinstalling the containers without the cache and it also did not work.

Unable to open remote display on Mac when running Docker

I have a Dockerfile written as below:
FROM joesan/raspi_opencv_3:latest
RUN apt-get update
RUN sudo apt-get install --no-install-recommends xserver-xorg
RUN sudo apt-get install --no-install-recommends xinit
RUN apt-get install -qqy x11-apps
RUN mkdir -p /raspi_motion_detection/project
WORKDIR /raspi_motion_detection/project
COPY ./ $WORKDIR/
COPY ./requirements.txt $WORKDIR/
ADD . $WORKDIR
CMD xclock
I have a Raspberry Pi to which I ssh from my Mac (running High Sierra).
Here is what I do:
I ssh into the RaspPi from my Mac
I execute the docker command using:
docker run -ti --device=/dev/vcsm \
--device=/dev/vchiq \
-e DISPLAY=$DISPLAY:0 \
-e XAUTHORITY=/.Xauthority \
-v /tmp/.X11-unix:/tmp/.X11-unix \
joesan/motion_detector
I get an error message as below:
Error: Can't open display: localhost:11.0:0
But when I just run xclock directly on the ssh terminal, I can see that the xclock window opens up.
So I could not understand why running xclock from within a Docker container would prevent the display port being opened? Any reasons? I also came across this post here and followed what has been described there, but i could not get it to work!
https://medium.com/#dimitris.kapanidis/running-gui-apps-in-docker-containers-3bd25efa862a
A bit simplified: Each docker container runs inside the docker daemon, which basically provides a stripped down os to each container. That os has no window manager.
That is why the command xclock inside a docker container exits with an error.
When you connect via ssh to your raspberry pi and call xclock it is executed inside the raspberry's os (propably raspian), which has a running window manager.
Ok! So I thinkI found the solution to my problem! Here is what I did!
Re-installed Raspberry Stretch Lite on my SD card. The old one seems to have gotten some stale files! You can skip this step, but for me there was some corrupt files on the old installation, so I decided to get a fresh install!
On my Raspberry Pi, run the following command:
xauth list
I copy the cookie locally to a text editor as I need it later!
Removed the xclock command from the Dockerfile that I originally had!
Build the Dockerfile using the following command:
docker run -it --net=host --device=/dev/vcsm --device=/dev/vchiq -e
DISPLAY -v /tmp/.X11-unix joesan/motion_detector bash
Notice that I'm running a bash command to my Docker run so that I can get a basj prompt from the running image!
The result of step 3 would give me a bash prompt from the container that I just ran at step 3
I need to now install xauth in the image
apt-get install xauth
I then add the xauth cookie from step 0
It is after this Bang! I got what I want!

Resources