安装Docker:
sudo apt install docker.io
#添加 docker 组
sudo groupadd docker
#用户加入 docker 组(免 sudo 权限)
sudo usermod -aG docker ${USER}
以制作ros2 humble docker 为例子:
Dockerfile:
FROM osrf/ros:humble-desktop
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 TZ=Asia/Shanghai DEBIAN_FRONTEND=noninteractive
COPY ./aliyun_sources.list_22.04 /etc/apt/
COPY ./timeline_frame.py /home
# COPY ./ros.key /usr/share/keyrings/ros-archive-keyring.gpg
RUN mv /etc/apt/sources.list /etc/apt/sources.list.back && \
mv /etc/apt/aliyun_sources.list_22.04 /etc/apt/sources.list && \
mv /home/timeline_frame.py /opt/ros/humble/lib/python3.10/site-packages/rqt_bag/timeline_frame.py && \
apt-get update && apt-get install -y apt-utils vim wget curl git git-lfs zip unzip zsh ssh \
openssh-server openssh-client tree tmux libpcap-dev ffmpeg iputils-ping ros-humble-compressed-image-transport \
build-essential g++ make cmake net-tools bash-completion sudo htop rsync gdb python3-pip && \
apt-get autoclean && rm -rf /var/lib/apt/lists/* && \
ln -s /usr/lib/x86_64-linux-gnu/libavdevice.so.58 /usr/lib/x86_64-linux-gnu/libavdevice.so
RUN echo "root:root" | chpasswd && \
echo "if [ -f /etc/bash_completion ] && ! shopt -oq posix; then" >> /root/.bashrc && \
echo " . /etc/bash_completion" >> /root/.bashrc && \
echo "fi" >> /root/.bashrc && \
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && \
echo "Port 22" >> /etc/ssh/sshd_config && \
echo "service ssh start > /dev/null 2>&1" >> /root/.bashrc
Makefile:
all:
@echo nothing special
# DOCKER_BASE := calmcar.com/docker/
DOCKER_NAME := ros2humble
DOCKER_TAG := 1.0
DOCKER_FULL_NAME := $(DOCKER_BASE)$(DOCKER_NAME):$(DOCKER_TAG)
docker_build:
docker build \
-t $(DOCKER_FULL_NAME) \
-f Dockerfile .
docker images --format "{{.Repository}}:{{.Tag}} -> {{.Size}}" $(DOCKER_FULL_NAME)
upload_artifactory:
cdt fm upload image $(DOCKER_NAME) $(DOCKER_TAG)
docker_pull:
docker pull $(DOCKER_FULL_NAME)
docker_test_base:
docker run --rm \
-v `pwd`:`pwd` \
-w `pwd` \
-it $(DOCKER_FULL_NAME) zsh
编译:
make docker_build
结果:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ros2humble 1.0 8a37e9b383cf 2 hours ago 3.78GB
转存tar与加载:
docker save -o ros2humble_v1.tar ros2humble:1.0
docker load -i ros2humble_v1.tar
运行docker: