-
Salutations to the one reading this. I am currently working on a project which requires me to use containers to run a program inside them. I built the app just fine (I think). When I try to run it, this is the output: Podman runs just fine normally. I also have Python module for Docker. And it runs just fine I tried running ls -l /run/podman/podman.sock and it said permission denied. Then I tried to look for fix, I ran chmod to give access but the output was same (even with root, though it shows output with sudo ls -l /run/podman/podman.sock) Here's the Python code: import docker
import podman
from podman import PodmanClient
from pathlib import Path
global ENGINE, PLATFORM, IMG_NAME
ENGINE = "podman"
PLATFORM = "Linux"
IMG_NAME = "nikto-img" # Normally I just import all 3 variables from config file but for the sake for problem I will just put them directly
# print("This test is just for all Python and Docker based things")
# def read_config():
# print("Checking for configuration file....")
# CONF_DIR = Path('.config')
# if CONF_DIR.is_file(): # If config file is already present, call main function
# print("Configuration file found!")
# f = open(".config","r") # Open config file
# lines = f.readlines()
# for i in lines: # Store values from config file into their respective (global) variables
# global PLATFORM, ENGINE, IMG_NAME
# if "OS"in i:
# PLATFORM = i.replace("OS: ", '')
# PLATFORM = PLATFORM.replace("\n", '')
# elif "ENGINE" in i:
# ENGINE = i.replace("ENGINE: ", '')
# ENGINE = ENGINE.replace("\n",'')
# elif "IMAGE" in i:
# IMG_NAME = i.replace("IMAGE: ", '')
# IMG_NAME = IMG_NAME.replace("\n",'')
# f.close()
# print(f'OS: {PLATFORM}',f'\nENGINE: {ENGINE}',f'\nIMAGE: {IMG_NAME}')
# else: # Else ask user to run setup script and exit the app
# print("Configuration file not present. Run setup script to make a new one.\nExiting app....")
# quit()
# read_config()
print(f"Testing {ENGINE}.....")
def podman_run(client, image, command): # I took help of AI for this.
container = client.containers.create(
image=image,
command=command,
remove=True,
detach=False
)
container.start()
logs = container.logs(stdout=True, stderr=True, stream=False)
return b''.join(logs).decode('utf-8').strip()
if ENGINE.lower() == "docker": # I have option for user if he got podman or docker
Client = docker.from_env()
log = Client.containers.run(IMG_NAME, "nikto -V")
log = log.strip().decode('utf-8')
print(log)
log = Client.containers.run(IMG_NAME, "echo Test successful.")
log = log.strip().decode('utf-8')
print(log)
elif ENGINE.lower() == "podman":
Client = PodmanClient(base_url="unix:///run/podman/podman.sock") # This is where my podman is stored too.
# Run container with Nikto command
log = podman_run(Client, f'{IMG_NAME}:latest', ["nikto", "-V"])
print(log)
# Run container with test command
log = podman_run(Client, f'{IMG_NAME}:latest', ["echo", "Test successful."])
print(log) I am running ParrotOS on VMWare Workstation 17. Here's what I got: Any help will be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Are you attempting to connect to a rootful podman socket from a non-root account? This is not allowed. Docker allows it because of the docker group. If you want to use rootless podman, you should be connecting to the rootless podman socket, not the rootful one. |
Beta Was this translation helpful? Give feedback.
-
Let me try, will let you know result. Edit 2: |
Beta Was this translation helpful? Give feedback.
In rootless mode you can start up the podman.socket service with
systemctl --user start podman.socket
Which should setup podman to listen on
$XDG_RUNTIME_DIR/podman/podman.sock