Dockerfile "RUN pip3 install --system ..." command

source: ros2-looker/Dockerfile-looker-base at main · Misterblue/ros2-looker · GitHub
Hi,
I want to modify the “ros2-looker/docker/Dockerfile-looker-base” dockerfile which runs Ros2:Foxy in a container under ubuntu 20.04 to Ros2:Humble under ubuntu 22.04.
This file contains commands “pip install --system” and “–system” do not pass when running dockerfile with 22.04.

Dockerfile : Dockerfile-ros2-base

# Create base image of Ubuntu 20.04 with ROS2 installed for arm64

# FROM arm64v8/ubuntu:20.04
#FROM ubuntu:20.04 ---------------------------------------------------------------------------
FROM ubuntu:22.04

RUN echo UTC > /etc/timezone

# Tell the libraries not to use the interactive dialogs
ENV DEBIAN_FRONTEND=noninteractive
ENV TERM=linux

# Update the image
RUN apt-get update \
    && apt-get upgrade -y

# ROS2 needs locale set to UTF-8
RUN apt-get install -y locales \
    && locale-gen en_US en_US.UTF-8 \
    && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG=en_US.UTF-8

# Utility packages
# 'tini' is SIGNAL handling wrapper for running the application
# 'apt-utils' is tools used for installing packages
RUN apt-get install -y tini apt-utils

# Packages needed for ROS2 installation
RUN apt-get install -y curl gnupg2 lsb-release

# Setup ROS2 repository keys
RUN apt-key adv --fetch-keys https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc \
    && sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list' \
    && apt-get update

# Install ROS2
# RUN apt-get install -y ros-foxy-ros-base --------------------------------------------------
RUN apt-get install -y ros-humble-ros-base

# Someday install OpenDDS
# https://github.com/objectcomputing/OpenDDS/releases/download/DDS-3.15/OpenDDS-3.15.tar.gz

# Bash command completion for python to make things easier
RUN apt-get install python3-argcomplete

# 'nonroot' user for running applications.
# Fixed user and group numbers for easier setting outside of the container
RUN adduser --disabled-password --uid 20000 --gecos 'non-root user for running app' nonroot
# USER nonroot

Dockerfile : Dockerfile-looker-base

# Create image with all Looker nodes
FROM misterblue/ros2-base

RUN echo UTC > /etc/timezone

# Tell the libraries not to use the interactive dialogs
ENV DEBIAN_FRONTEND=noninteractive
ENV TERM=linux

# Get needed installation and debugging tools
RUN apt-get update \
    && apt-get install -y vim git curl wget

# Get all the needed Python tools
RUN apt-get install -y python-dev python3-pip python3-colcon-common-extensions

# Get Raspberry Pi Python tools
RUN apt-get install -y i2c-tools python3-smbus

# Get the AdaFruit tools for accessing the PWMHAT
RUN cd \
    && git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git \
    && cd Adafruit_Python_PCA9685 \
    && python3 setup.py install

RUN cd \
    && pip3 install --system Adafruit-GPIO

# OpenCV
# Installing 'headless' means Qt and X11 bindings not pulled in
RUN cd \
    && pip3 install opencv-python-headless

# Install CvBridge and othe vision processing for ROS2/OpenCV use
# RUN apt-get install -y ros-foxy-cv-bridge \
#     && apt-get install -y ros-foxy-vision-opencv
RUN apt-get install -y ros-humble-cv-bridge

# Use the version of v4l2 that has been updated for python3
RUN pip3 install git+https://github.com/aspotton/python3-v4l2.git

# Add Python libraries used by the nodes (as separate layers if any errors)
RUN pip3 install --system imageio
RUN pip3 install --system dlib
pi@pi-desktop:~/ros2-looker/src/ros2-looker-main/docker$ ./buildLookerBase.sh 
[...]
 => ERROR [ 7/12] RUN cd     && pip3 install --system Adafruit-GPIO        2.5s
------                                                                          
 > [ 7/12] RUN cd     && pip3 install --system Adafruit-GPIO:                   
#0 2.101                                                                        
#0 2.101 Usage:                                                                 
#0 2.101   pip3 install [options] <requirement specifier> [package-index-options] ...                                                                           
#0 2.101   pip3 install [options] -r <requirements file> [package-index-options] ...
#0 2.101   pip3 install [options] [-e] <vcs project url> ...
#0 2.101   pip3 install [options] [-e] <local project path> ...
#0 2.101   pip3 install [options] <archive url/path> ...
#0 2.101 
#0 2.101 no such option: --system
------
Dockerfile-looker-base:26
--------------------
  25 |     
  26 | >>> RUN cd \
  27 | >>>     && pip3 install --system Adafruit-GPIO
  28 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c cd     && pip3 install --system Adafruit-GPIO" did not complete successfully: exit code: 2
pi@pi-desktop:~/ros2-looker/src/ros2-looker-main/docker$ ^C
p
[

Not everything is Docker’s fault when a command runs in a container :slight_smile:
Different Ubuntu version, different default pip version and the latest pip does not have the --system option.

When something doesn’t work in a container or during the build, it is the best to try it manually in a running container using the same versions and check the available parameters.
.