Search code examples
dockerros

How to share apt-package across Docker containers


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

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 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.

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


Solution

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

    Example:

    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 . 
    

    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
    

    Now build the second images:

    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.

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

    This example can be expanded multiple times.