【问题标题】:Need guidance for creating temporary docker container for generating file on host machine需要创建临时 docker 容器以在主机上生成文件的指导
【发布时间】:2021-04-09 18:52:12
【问题描述】:

我想创建一个 docker 容器,它可以读取名为 helloworld.proto 的文件并运行命令

protoc --dart_out=grpc:lib/src/generated -Iprotos protos/helloworld.proto

容器将从所有依赖项开始,并使用主机可以访问的 gRPC 生成所需的文件。这可以实现吗?

【问题讨论】:

    标签: docker wsl-2 grpc-dart


    【解决方案1】:

    如果您的进程的主要目标是从主机系统读取文件并将文件写回主机系统,您会发现直接在主机系统上运行进程并且不涉及 Docker 会容易得多。

    原则上,您可以使用 Docker bind mounts 使主机目录对容器可见。但是,特别是对于一次性命令,启动容器所需的命令行长度将比您尝试运行的命令的长度长:

    sudo \                    # docker run can take over the host so root is required
    docker run \
      --rm \                  # delete the container when done
      -v "$PWD:/data" \       # make host directive visible to container
      -w /data \              # make mounted directory current working directory
      -u $(id -u):$(id -g) \  # write files as current host user
      some-image-containing-protoc \
      proton --dart-out=grpc:lib/src/generated -Iprotos protos/helloworld.proto
    

    通常只需一个命令(sudo apt-get install protobuf-compilerbrew install protobuf)即可在主机系统上全局安装protoc,这通常更易于管理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多