Containers

There are two major Containers used, docker and podman. Docker however require root access, but podman does not. We can install any Operating system image using the command:

docker/podman pull Os_image_name

once it is installed, we will start the image by following command:
Running a container without mounting any directory:

podman run -d -t --name rocky9.2 rockylinux/rockylinux:9.2

here rocky9.2 can be any name you assign to image rockylinux:9.2
once it runs, we can see the processes using the command

podman ps

and run the command
podman exec -it rocky9.2 bash

Try the following commands

```

  1. podman images (to see list of all pulled images)
  2. podman stop rocky9.2 ( to stop the container from running )
  3. podman start rocky9.2 ( to start it once again_)

```

Mounting and unmounting

To run a container with mounted host directories using Podman, you can use the -v or --volume option to create bind mounts. Bind mounts allow you to link directories on your host system to directories inside the container. Here's how you can do it:

```bash
podman run -it --name my-container -v /path/to/host/directory:/path/in/container IMAGE_NAME
```

For example, if you want to mount a directory named my_data located in your home directory on the host to the /data directory in the container, you can run:

```bash
podman run -it --name my-container -v ~/my_data:/data my-image
```

Once the container is running with the bind mount, any changes made to the /data directory inside the container will be reflected in the ~/my_data directory on your host system, and vice versa. This allows for easy sharing of files and data between the host and the container.

Tried

Here I have installed rockylinux 9.2 image and made an container named as virat, I have mounted the /home/vishal of host to /home/vishal of container.

To exit form container, simply type "exit" and hit enter.

To enter again the intereactive bash shell to the container, simply use the alias created , just type "virat" and hit enter in command prompt. You can check it.

To unmount the directories, use : podman stop rockybalboa

to restart, use : podman start virat && virat

To list all containers, use "podman ps -a", use


podman rm container_name.

To remove the images: first we have to stop container podman stop container_name and then remove the container by podman rm container_name, and then only we can remove the images by podman rmi image_name.

https://medium.com/analytics-vidhya/backup-export-docker-image-easily-4f6970d225a6#:~:text=Backup%20the%20Container%20and%20Restore,used%20to%20launch%20another%20container.

Making images from commited containers

the below command will create an updated image:

podman commit container_name image_name

To save to .tar file and download it to local system or transfer to some ssd drive, we can :


podman save -o output.tar image1 image2 ...

To load the image from the .tar file on another system, you can use the podman load command:

podman load -i image_name.tar

To add gpu to runtime:

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/cdi-support.html

follow above or simply execute the below command:

podman run -d -t --device nvidia.com/gpu=all --security-opt=label=disable --name sachin cuda_virat:latest

In above command, -d means run in background, -t means tty support, --name is nickname for container and cuda_virat:latest is name of image we commited by:


podman commit cuda_vira virat

To add all gpu and have graphic access

podman run -d -t --device nvidia.com/gpu=all --security-opt=label=disable -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --net=host --name virat cuda_vim:latest

Below is from chatgpt(have not yet tried by me):

In the context of Podman containers on a server, the concept of user sessions and lingering is typically associated with the host system rather than individual containers. Containers are isolated environments that run on the host, and their lifecycle is managed by the container runtime (such as Podman or Docker).

If you want certain processes or services to continue running even when the user logs out of the host system, you generally need to manage that at the host level, not within the container. The container itself doesn't have direct control over the host's user sessions.

If you have specific processes or services within a Podman container that you want to keep running persistently, you may want to consider approaches such as:

  1. *Run the Container in the Background:* When you start a container with Podman, you can use the -d option to run it in the background. This allows the container to continue running even after the terminal session is closed. ```bash podman run -d your_image ```
  2. *Use Systemd Service:* You can create a systemd service on the host system that manages the lifecycle of your container. This allows you to start, stop, and manage the container as a system service. Create a systemd service file, for example, mycontainer.service: ```ini [Unit] Description=My Container [Service] ExecStart=/usr/bin/podman run your_image Restart=always User=your_username Group=your_groupname [Install] WantedBy=default.target ``` Adjust the ExecStart, User, and Group parameters according to your setup. Then, enable and start the service: ```bash sudo cp mycontainer.service /etc/systemd/system/ sudo systemctl enable mycontainer.service sudo systemctl start mycontainer.service ```

Remember that these approaches are host-centric. If you need more fine-grained control within the container itself, you may need to manage the processes or services directly within the container using tools appropriate for your containerized application.

Errors and solutions

  1. gpu9_not_found
  2. nasstorage_content_issue