Singularity, get started quickly and take you to fly

Singularity introduction

Singularity is a container technology. Users can package the software locally into an image and upload it to the server for operation. Because the user has root permission on the local computer and also has root permission when making the container image of the software, it is more flexible when deploying and installing applications.

(I need ROS when landing the algorithm. When using the supercomputing resource deployment environment of the school, I can't get sudo permission. Therefore, migrant workers can only consult the data themselves and find that they can solve it with the Singularity provided by the cluster, so they start self-study and give more advice!)

First, use ubuntu:16.04 image to experience how to use singularity

Get image:

First, obtain the precompiled image from the Singularity Hub or Docker Hub.

$ singularity pull ubuntu:16.04  # Select the version as needed

Then you can get Ubuntu in the current directory_ 16.04.sif document.

Run mirror:

You can use shell commands to connect to the container and run commands.

$ singularity shell ubuntu_16.04.sif
Singularity> pwd
/home/tutuzi

Create instance:

Simply create two instances. After success, instance started successfully will be displayed.

$ singularity instance start ubuntu_16.04.sif test1
$ singularity instance start ubuntu_16.04.sif test2

View instance:

You can view the DAEMON NAME, PID, CONTAINER IMAGE information corresponding to each instance.

$ singularity instance list

Stop instance:

Stop the two instances of test1 and test2 created before.

$ singularity instance stop test1
$ singularity instance stop test2

Create containers based on Ubuntu 16.04

For specific steps, see: This note: run Singularity

Relevant notes, problems encountered in my practice and corresponding solutions are as follows:

Install the singularity section:

  • I can only install and use singularity on Linux system. The computer with root permission is win10 system, so I need to use virtual machine to create image.
    (if the installation and configuration required in this step are also required, please refer to the following steps for details, which are valid through personal test!!)
ITEMREFERENCE
VMware Workstation Pro v16https://www.ruanhuicn.com/soft/vmware-workstation-pro.html
Ubuntu18.04 isohttp://mirrors.aliyun.com/ubuntu-releases/18.04/
Recommended: CentOS7http://mirrors.aliyun.com/centos/7/isos/x86_64/
Installing Ubuntu on VMwarehttps://cloud.tencent.com/developer/article/1571849
#Installation dependency:
sudo yum install -y gcc libuuid-devel squashfs-tools openssl-devel

#Install go
export VERSION=1.15 OS=linux ARCH=amd64   
wget https://dl.google.com/go/go$VERSION.$OS-$ARCH.tar.gz 
sudo tar -C /usr/local -xzvf go$VERSION.$OS-$ARCH.tar.gz
sudo rm -f go$VERSION.$OS-$ARCH.tar.gz
sudo vim /etc/profile
#Add export PATH=/usr/local/go/bin:$PATH
source /etc/profile
sudo vim /etc/sudoers
#Add / usr/local/go/bin / to Defaults secure_path

#Install singularity. The installed version here is 3.6.2 
export VERSION=3.6.2 
wget https://github.com/hpcng/singularity/releases/download/v${VERSION}/singularity-${VERSION}.tar.gz 
tar -xzf singularity-${VERSION}.tar.gz
cd singularity
./mconfig
cd builddir/
sudo make && sudo make install
sudo rm -rf singularity*

To create a singularity image:

Refer to official documents: https://singularity.hpcng.org/user-docs/3.2/quick_start.html#singularity-definition-files

Singularity v3.0 and above produces immutable images in the Singularity Image File (SIF) format. This ensures reproducible and verifiable images and allows for many extra benefits such as the ability to sign and verify your containers.

How to create a sandbox to create an image:

su
singularity build --sandbox ./tutu_box docker://ubuntu:16.04
singularity shell -w ./tutu_box
apt-get -y update
apt-get -y install python2-minimal python-dev

For ROS installation, please refer to the official website http://wiki.ros.org/kinetic/Installation/Ubuntu.

  • Configure your Ubuntu repositories:
    # apt-get install software-properties-common
    add-apt-repository universe
    add-apt-repository multiverse
    add-apt-repository restricted
    apt-get update
    
  • Setup your sources.list:
    sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
    
  • Setup your keys:
    apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
    
  • Installation:
    apt-get update
    apt-get install ros-kinetic-desktop-full
    
  • Environment setup:
    echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    
  • Dependencies for building packages
      apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
    
      rosdep init
      rosdep update
    

Next, let's talk about using Definition file To create a SIF container environment (ROS):

A Singularity Definition file is divided into two parts: Header & Section

BootStrap: docker
From: ubuntu:16.04

%post
    apt-get -y update
    apt-get install sudo
    apt-get install python-minimal python-dev
    
	apt-get install software-properties-common
	add-apt-repository universe
   	add-apt-repository multiverse
   	add-apt-repository restricted
   	apt-get update
   	sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
	apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
	
	apt-get update
	apt-get install ros-kinetic-desktop-full
	
	apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
	
%environment
	echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
	source ~/.bashrc

%runscript
	rosdep init
	rosdep update

%labels

Test whether ROS can operate normally

source  ~/.bashrc
# Run the following three commands in the three terminal
roscore  # terminal 1 startup environment
rosrun turtlesim turtlesim_node  # terminal 2 Little Turtle
rosrun turtlesim turtle_teleop_key  # terminal 3 direction key can control the movement of the little turtle

Tags: Linux Ubuntu Container

Posted on Thu, 07 Oct 2021 11:59:09 -0400 by ukspudnie