docker / for-mac

Bug reports for Docker Desktop for Mac
https://www.docker.com/products/docker#/mac
2.44k stars 118 forks source link

SocketCAN & vcan support #4405

Closed Clovel closed 4 years ago

Clovel commented 4 years ago

Description

We cannot use SocketCAN's VirtualCAN bus (vcan) on a Linux Docker container w/ Docker for Mac.

Rationale

One of the many advantages of Docker for macOS is to be able to test Linux related code and features without requiring the need of a full fledged VM (Parallels, VMWare, Virtual Box) and having a lightweight Linux running while we can develop our projects.

One feature I would like to have on my Mac is SocketCAN. As it or a alternative is sadly unavailable for macOS, I would like to test my programs with VirtualCAN (vcan).

The Linux Kernel used by Docker for Mac - LinuxKit if I understand correctly - is not compiled with the CAN related configuration flags. This should be addressed.

Expected behavior

Linux Kernel (LinuxKit) should have the following configuration flags for a (near) full CAN protocol support :

#
# CAN Bus support
#

CONFIG_CAN=m
CONFIG_CAN_RAW=m
CONFIG_CAN_BCM=m
CONFIG_CAN_GW=m

#
# CAN Device Drivers
#
CONFIG_CAN_VCAN=m
CONFIG_CAN_SLCAN=m
CONFIG_CAN_DEV=m
CONFIG_CAN_CALC_BITTIMING=y
CONFIG_CAN_MCP251X=m
CONFIG_PCH_CAN=m
CONFIG_CAN_SJA1000=m
CONFIG_CAN_SJA1000_PLATFORM=m
CONFIG_CAN_EMS_PCMCIA=m
CONFIG_CAN_EMS_PCI=m
CONFIG_CAN_PEAK_PCI=m
CONFIG_CAN_KVASER_PCI=m
CONFIG_CAN_PLX_PCI=m
CONFIG_CAN_C_CAN=m

#
# CAN USB interfaces
#
CONFIG_CAN_EMS_USB=m
CONFIG_CAN_ESD_USB2=m
CONFIG_CAN_SOFTING=m
CONFIG_CAN_SOFTING_CS=m
# CONFIG_CAN_DEBUG_DEVICES is not set

For a more streamlined and lightweight approach, maybe this could suffice :


#
# CAN Bus support
#

CONFIG_CAN=m
CONFIG_CAN_RAW=m
CONFIG_CAN_BCM=m
CONFIG_CAN_GW=m

#
# CAN Device Drivers
#
CONFIG_CAN_VCAN=m
CONFIG_CAN_DEV=m

Actual behavior

Modules are not available. The following setup commands are not possible :

$ modprobe vcan
$ sudo ip link add dev vcan0 type vcan
$ sudo ip link set up vcan0

Information

Steps to reproduce the behavior

  1. Use this Dockerfile :
    
    # Source image ----------------------------------
    FROM alpine:latest

Update package manager ------------------------

RUN apk update RUN apk upgrade

Update/install packages -----------------------

RUN apk add --no-cache \ linux-headers \ dumb-init \ musl \ bash \ ca-certificates \ git \ wget \ curl \ tar \ unzip \ coreutils \ gcc \ gdb \ cmake \ make \ pkg-config \ doxygen \ graphviz \ openssh \ net-tools \ vim \ nano \ python3 \ python3-pip

RUN apt install -y can-utils

Install pip3 packages

RUN pip3 install --no-cache --upgrade pip setuptools wheel && \ if [[ ! -e /usr/bin/pip ]]; then \ ln -s pip3 /usr/bin/pip; \ fi RUN pip3 install --no-cache canopen ``

  1. Attempt to load the vcan kernel module
    $ modprobe vcan
  2. Get the following error (not copy pasted, I am away from my dev machine) :
    modprobe: ERROR: ../libkmod/libkmod.c:XXX kmod_search_moddep() could not open moddep file '/lib/modules/4.19.76-linuxkit/modules.dep.bin' modprobe:
    FATAL: Module vcan not found in directory /lib/modules/4.19.76-linuxkit

Action

I will submit a PR to the LinuxKit repository to try and have this feature merged. EDIT : I submitted the PR : linuxkit/linuxkit#3486. I am currently trying to test this on macOS, but I am having some difficulties.

Side notes

This issue seems to have been under discussion over at the LinuxKit repository :

I saw others were having similar difficulties with the SCTP protocol kernel module. I believe a fix was merged in LinuxKit.

ulrich commented 4 years ago

Hello @Clovel

This is a misconfiguration LinuxKit side only, no?

Clovel commented 4 years ago

Hello @ulrich. It does seem so for the "code" part. Yet merging this functionality in the default kernel used by Docker for Mac is up to the Docker community. And the issue I have comes from using Docker for Mac, hence why I submitted an issue here.

ulrich commented 4 years ago

OK, so the feature is already enabled in LinuxKit and it is not available in docker desktop. Is it that? I don't think the CAN support is fully operational in LinuxKit or I have wrong?

Sorry the need of explanations, but I am lost in your two PR in LinuxKit. One was merged and the second one is open again.

Clovel commented 4 years ago

No, it is not yet included. I submitted a PR over at linuxkit : https://github.com/linuxkit/linuxkit/pull/3486.

The one that is merged only affect one sub product (an example ou something like that) of the linuxkit project and is not mine.

Mine changes the main kernel configurations.

Clovel commented 4 years ago

I am currently trying to make this work, but am having difficulties. I post my progress and my issues over at https://github.com/linuxkit/linuxkit/pull/3486.

I am under the impression that I am not testing this correctly.

ulrich commented 4 years ago

So, when the feature will be fully include in LinuxKit so Docker Desktop will support it.

Clovel commented 4 years ago

So, when the feature will be fully include in LinuxKit so Docker Desktop will support it.

I think so.

willbotics commented 4 years ago

@Clovel are you waiting for LinuxKit to approve your changes or still working out a solution?

Clovel commented 4 years ago

Hi @Willcampbellmelb. As my last comment on https://github.com/linuxkit/linuxkit/pull/3486 states, I can’t even build the kernel with the appropriate build steps. I got no answer to my plea for help, so I guess I’m stuck.

I reported my steps, platform and results to either this issue or (mainly) the PR linked in this comment.

docker-robott commented 4 years ago

Issues go stale after 90 days of inactivity. Mark the issue as fresh with /remove-lifecycle stale comment. Stale issues will be closed after an additional 30 days of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle stale

Clovel commented 4 years ago

This issue is LinuxKit related, but the associated LinuxKit issue has not yet been closed. This issue can be either closed or set to pending.

docker-robott commented 4 years ago

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle locked