如何在 Docker 容器构建中包含 Webots?

问题描述

我想将 Webots 添加到我的 Dockerfile,但我遇到了一个问题。我当前的手动安装步骤(来自 here)是:

$ # launch my Docker container without Webots
$ wget -qO- https://cyberbotics.com/Cyberbotics.asc | sudo apt-key add -
$ sudo apt update
$ sudo apt install -y software-properties-common
$ sudo apt-add-repository 'deb https://cyberbotics.com/debian/ binary-amd64/'
$ sudo apt update
$ sudo apt-get install webots
$ # now I have a Docker container with Webots

我想在 Docker 容器的构建中包含这个过程。不过,我不能只在 Dockerfile 中使用相同的步骤,因为在安装 webots 时,它会提示一些标准输入响应,询问键盘的原产国。由于Docker在构建时不听stdin,我无法回答这些提示。我尝试像这样管道 echo 输出,但它不起作用

# Install Webots (a robot simulator)
RUN wget -qO- https://cyberbotics.com/Cyberbotics.asc | sudo apt-key add -
RUN apt-get update && sudo apt-get install -y \
               software-properties-common \
               libxtst6
RUN sudo apt-add-repository 'deb https://cyberbotics.com/debian/ binary-amd64/'
RUN apt-get update && echo 31 1 | sudo apt-get install -y \
               webots  # the echo fills the "keyboard country of origin" prompts

如何将 Webots 包含在 Docker 容器中?我不想只使用别人的容器(例如 cyberbotics/webots-docker),因为我需要向容器添加其他东西,例如 ROS2。

解决方法

编辑:这个答案是不正确的。 FROM 不是这样工作的,只会使用最后一个 FROM 语句。

原答案:

结果比我预期的要简单。您可以在 Dockerfile 中包含多个 FROM $IMAGE 语句以组合基础镜像。这是一个解释我所做的事情的示例(请注意,all ARG 语句必须出现在第一个 FROM 语句之前):

ARG BASE_IMAGE_WEBOTS=cyberbotics/webots:R2021a-ubuntu20.04
ARG IMAGE2=other/image:latest

FROM $BASE_IMAGE_WEBOTS AS base
FROM $IMAGE2 AS image2

# other things needed

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...