如何在Docker容器之间共享apt-package [英] How to share apt-package across Docker containers

查看:57
本文介绍了如何在Docker容器之间共享apt-package的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用docker帮助我保持组织结构,以使用ROS(机器人操作系统)开发和部署程序包/系统.

I want to use docker to help me stay organized with developing and deploying package/systems using ROS (Robot Operating System).

我想为各种软件提供多个容器/映像,并为单个映像提供所有ROS依赖项.如何让一个容器使用我的依赖项主容器中的apt-packaged?

I want to have multiple containers/images for various pieces of software, and a single image that has all of the ROS dependencies. How can I have one container use the apt-packaged from my dependency master container?

例如,我可能有以下容器:

For example, I may have the following containers:

  • MyRosBase: sudo apt-get install 我需要的所有ros依赖项(有很多).设置其他一些环境变量和各种配置项.
  • MyMoveApplication:使用MyRosBase的依赖项,并将任何其他特定的依赖项安装到此映像.然后运行可移动机器人手臂的软件.
  • MySimulateApplication:使用MyRosBase的依赖项,并将任何其他特定的依赖项安装到此映像.然后运行模拟机器人手臂的软件.
  • MyRosBase: sudo apt-get install all of the ros dependencies I need (There are many). Set up some other Environment variables and various configuration items.
  • MyMoveApplication: Use the dependencies from MyRosBase and install any extra and specific dependencies to this image. Then run software that moves the robot arm.
  • MySimulateApplication: Use the dependencies from MyRosBase and install any extra and specific dependencies to this image. Then run software that simulates the robot arm.

如何使用另一个容器中的容器中的apt软件包,而不必每次都在每个容器上重新安装它们?

How do I use apt packages from container in another container without reinstalling them on each container each time?

推荐答案

您可以使用Dockerfile创建自己的映像,将其用作基础映像.

You can create your own images that serve you as base images using Dockerfiles.

示例:

mkdir ROSDocker
cd ROSDocker
vim Dockerfile-base

FROM debian:stretch-slim
RUN apt-get install dep1 dep2 depn

sudo docker build -t yourusername/ros-base:0.1 -f Dockerfile-base . 

构建完成后,您可以从该基础映像中创建另一个docker文件.

After the build is complete you can create another docker file from this base image.

FROM yourusername/ros-base:0.1
RUN apt-get install dep1 dep2 depn

现在构建第二个图像:

sudo docker build -t yourusername/mymoveApplication:0.1 -f Dockerfile-base .

现在您已经为移动应用程序创建了一个映像,从该映像运行的每个容器都将安装所有依赖项.

Now you have an image for your move application, each container that you run from this image will have all the dependencies installed.

您可以拥有docker映像存储库,用于管理您构建的映像并在人与环境之间共享.

You can have docker image repository for managing your built images and sharing between people/environments.

此示例可以扩展多次.

这篇关于如何在Docker容器之间共享apt-package的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆