Table of Contents
This article explains that the utilization of Container technology on Linux generates particular Python environments, driving the Selenium automation browser.
Generally speaking, we do not want to modify and destroy our Linux PC environments because of some programming tests and their fancy environments. But, utilizing Containers will allow readers to build compact, lightweight, and reproducible virtual operating systems without destroying environments of PC.
Utilizing Singularity Containers for Python Environments
What is Container?
This answer is straight-forward. It's the open-source lightweight virtual operating systems using the host Linux kernel. The performance after containerization is, in general, much better than full virtualized machines such as VMWare, VirtualBox, and so on.
Let's imagine if you have a program developed by you on your PC, which has been driven by a particular Linux distribution such as Ubuntu 18. You confirmed it worked on your PC. But, what happens if you install it into the other PC using older Ubuntu distributions?
The simplest way is building the other Linux and distribution environments with particular programming libraries you've used, and let's run your program.
We can use the Containers as lightweight production environments, without considering complicated configurations in the Linux OS.
So, your program will work as if it's in a CONTAINER without knowing the complex inside content.
Docker
Docker is the most popular for providing container platform, image distributor (DockerHub), and execution environments developed by the Docker company. We can quickly write the virtual operating system configuration in the Docker configuration called Dockerfile.
For example, we can define CentOS7 and installing the Firefox browser. We write a Dockerfile.
1 2 3 4 5 |
FROM centos:7 ## Installing some tools RUN yum -y install epel-release RUN yum -y install firefox |
Once we execute a docker command, we can build an image of the virtual operating system.
1 2 3 4 5 6 7 8 9 10 11 |
$ docker build -t firefox-centos7 . Sending build context to Docker daemon 2.56 kB Step 1/3 : FROM centos:7 ---> 67fa590cfc1c Step 2/3 : RUN yum -y install epel-release ---> Using cache ---> 52e48a286406 Step 3/3 : RUN yum -y install firefox ---> Using cache ---> b5cd48659c68 Successfully built b5cd48659c68 |
Then run the container.
1 2 3 4 5 6 7 |
$ docker run --rm -it firefox-centos7 /bin/bash [root@d2614014183e /]# firefox -version Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11 Running without a11y support! Mozilla Firefox 68.12.0esr [root@d2614014183e /]# |
Docker command is a client for interacting with the Docker daemon through the CLI.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
$ docker help Usage: docker COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/a/home/local/gen/.docker") -D, --debug Enable debug mode --help Print usage -H, --host list Daemon socket(s) to connect to (default []) -l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/a/home/local/gen/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/a/home/local/gen/.docker/cert.pem") --tlskey string Path to TLS key file (default "/a/home/local/gen/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: container Manage containers image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker volume Manage volumes Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes |
Singularity
Singularity is an open source-based container platform designed for scientific and High-Performance Computing environments with the following features.
- Containers can be started and stopped with a general user account. You do not need to grant sudo privileges to your user account.
- Docker images are available.
- The owner of the user account in the container is inherited from the host PC. Even if you create and edit a file in a container, the owner remains.
- Supports GPU virtualization
- Bind (share) under $ HOME on the host to the container
- By default, the container instance can share the home directory. So, it is easy to move and copy data from and to your home director.
- If the system administrator allows the user to bind, the user can also specify the bind source and destination.
Instlling Singularity
In Ubuntu Linux
1 2 |
$ sudo apt-get update $ sudo apt-get install singularity-container |
In CentOS Linux
1 2 |
$ sudo yum install epel-release $ sudo yum install singularity |
Basic commands of Singualrity
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
$ singularity Usage: singularity [global options...] <command> Available Commands: build Build a Singularity image cache Manage the local cache capability Manage Linux capabilities for users and groups config Manage various singularity configuration (root user only) delete Deletes requested image from the library exec Run a command within a container inspect Show metadata for an image instance Manage containers running as services key Manage OpenPGP keys oci Manage OCI containers plugin Manage Singularity plugins pull Pull an image from a URI push Upload image to the provided URI remote Manage singularity remote endpoints run Run the user-defined default command within a container run-help Show the user-defined help for an image search Search a Container Library for images shell Run a shell within a container sif siftool is a program for Singularity Image Format (SIF) file manipulation sign Attach digital signature(s) to an image test Run the user-defined tests within a container verify Verify cryptographic signatures attached to an image version Show the version for Singularity |
Let's build the latest CentOS operating system on a Singularity container. We build the singularity image file as centos7.sif.
1 |
$ sudo singularity build centos7.sif docker://docker.io/centos:7 |
Now, we can access the container by shell.
1 2 |
$ singularity shell centos7.sif Singularity> |