小编zje*_*fer的帖子

docker-compose:如果未找到设备,则忽略设备映射

在 docker-compose.yml 中定义这样的设备映射时:

version: "3.8"

services:
  app:
    build: .
    devices:
      - /dev/video0:/dev/video0
Run Code Online (Sandbox Code Playgroud)

如果在主机系统上没有 /dev/video0 的情况下启动此容器,容器将崩溃并出现以下错误:

Error response from daemon: error gathering device information while adding custom device "/dev/video0": no such file or directory

  1. 如果设备不存在,是否可以启动容器,忽略错误?
  2. 如果我稍后在容器运行时连接设备,是否也可以将其自动安装到容器中?

docker docker-compose

15
推荐指数
1
解决办法
1501
查看次数

属性更改时如何引发错误?

我想确保当在类外更改对象的属性时引发错误。这是我尝试执行的操作:

class Example {
  constructor(index) {
    this.index = index;

    Object.defineProperty(this, 'index', {
      set() {
        throw new AssertionError("can't set attribute");
      }
    });
  }
}

class AssertionError extends Error {
  constructor(message) {
    super();
    this.name = "AssertionError";
    this.message = message;
  }
}


let example = new Example(5);
console.log(example.index); //prints undefined instead of 5
example.index = 10; // I want to throw an AssertionError here
Run Code Online (Sandbox Code Playgroud)

就像我想要的那样抛出错误,但是索引值未定义。我仍然希望能够在类内部更改属性,但是我想防止属性在类外部更改。

javascript

10
推荐指数
1
解决办法
78
查看次数

标签 统计

docker ×1

docker-compose ×1

javascript ×1