From bdf24daa2dbced8348abf117c14511819be2b47c Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 13 Jan 2025 11:20:15 -0500 Subject: [PATCH] Fix ramalama run on docker to work correctly Also always pull newer images when doing run and serve. Fixes: https://github.com/containers/ramalama/issues/542 Signed-off-by: Daniel J Walsh --- docs/ramalama.1.md | 2 +- ramalama/model.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/ramalama.1.md b/docs/ramalama.1.md index bb46ef05..eab3e68d 100644 --- a/docs/ramalama.1.md +++ b/docs/ramalama.1.md @@ -19,7 +19,7 @@ Running in containers eliminates the need for users to configure the host system RamaLama pulls AI Models from model registries. Starting a chatbot or a rest API service from a simple single command. Models are treated similarly to how Podman and Docker treat container images. -When both Podman and Docker are installed, RamaLama defaults to Podman, The `RAMALAMA_CONTAINER_ENGINE=docker` environment variable can override this behavior. When neither are installed RamaLama attempts to run the model with software on the local system. +When both Podman and Docker are installed, RamaLama defaults to Podman, The `RAMALAMA_CONTAINER_ENGINE=docker` environment variable can override this behaviour. When neither are installed RamaLama attempts to run the model with software on the local system. Note: diff --git a/ramalama/model.py b/ramalama/model.py index ba8483bb..f34c58fd 100644 --- a/ramalama/model.py +++ b/ramalama/model.py @@ -154,6 +154,11 @@ def setup_container(self, args): if os.path.basename(args.engine) == "podman": conman_args += ["--pull=newer"] + elif os.path.basename(args.engine) == "docker": + try: + run_cmd([args.engine, "pull", "-q", args.image], ignore_all=True) + except Exception: # Ignore errors, the run command will handle it. + pass if sys.stdout.isatty() or sys.stdin.isatty(): conman_args += ["-t"] @@ -201,9 +206,9 @@ def exec_model_in_container(self, model_path, cmd_args, args): return False if model_path and os.path.exists(model_path): - conman_args += [f"--mount=type=bind,src={model_path},destination={MNT_FILE},rw=false"] + conman_args += [f"--mount=type=bind,src={model_path},destination={MNT_FILE},ro"] else: - conman_args += [f"--mount=type=image,src={self.model},destination={MNT_DIR},rw=false,subpath=/models"] + conman_args += [f"--mount=type=image,src={self.model},destination={MNT_DIR},ro,subpath=/models"] # Make sure Image precedes cmd_args. conman_args += [self._image(args)] + cmd_args