Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use libpod as library in my own program? #3445

Closed
towe75 opened this issue Jun 27, 2019 · 2 comments
Closed

How to use libpod as library in my own program? #3445

towe75 opened this issue Jun 27, 2019 · 2 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@towe75
Copy link
Contributor

towe75 commented Jun 27, 2019

/kind feature

Build a stand alone program with libpod features

I'd like to work on integrating podman and nomad, see also hashicorp/nomad#5312

So i started out to build a test program where i want to get familiar with the libpod api before building the actual nomad plugin.

I did not have any trouble building the tool but i can not manage to get a libpod.Runtime object.

Also there seems to be no official documentation on using libpod as library (the project name, however, suggests that it should be possible :-) )

Steps to reproduce the issue:

  1. write a cli tool with this source code
package main

import (
	"context"

	"github.com/containers/libpod/libpod"
	"github.com/sirupsen/logrus"
)

func main() {

	logrus.SetLevel(logrus.TraceLevel)
	logrus.Info("Getting Runtime")

	ctx := context.TODO()
	runtime, err := libpod.NewRuntime(ctx)
	if err != nil {
		logrus.Fatal("Error creating runtime", err)
		return
	}

	containers, err := runtime.GetContainers()
	if err != nil {
		logrus.Fatal("Error listing containers", err)
		return
	}

	for _, c := range(containers) {
		logrus.Info("Found container", c.Name())

	}

	runtime.Shutdown(false)
  1. Run the program

The program will block forever, it can not initialize the runtime at all

Debug info

Logging output

INFO[0000] Getting Runtime
DEBU[0000] Initializing boltdb state at /var/lib/containers/storage/libpod/bolt_state.db
DEBU[0000] Using graph driver overlay
DEBU[0000] Using graph root /var/lib/containers/storage
DEBU[0000] Using run root /var/run/containers/storage
DEBU[0000] Using static dir /var/lib/containers/storage/libpod
DEBU[0000] Using tmp dir /var/run/libpod
DEBU[0000] Using volume path /var/lib/containers/storage/volumes
DEBU[0000] Set libpod namespace to ""
DEBU[0000] [graphdriver] trying provided driver "overlay"

Process list

153 ? Ss 0:00 /bin/bash
820 ? Sl+ 0:00 _ ./libpod-test
827 ? Sl+ 0:00 _ storage-mountfrom /var/lib/containers/storage

Questions

  1. do i miss any initialization step? Maybe you can clearify the start/stop cycle of the library a bit.
  2. it would be helpful to build and link the godoc for libpod. Getting started was rather complex

For sure i miss some important initialization step but i can not find any clue in the github repo.

Thank you,

Thomas

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 27, 2019
@mheon
Copy link
Member

mheon commented Jun 27, 2019 via email

@towe75
Copy link
Contributor Author

towe75 commented Jun 27, 2019

@mheon you made my day!
Still having some better documentation would be awesome.

Thank you!

Cheers,

Thomas

@towe75 towe75 closed this as completed Jun 27, 2019
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Categorizes issue or PR as related to a new feature. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

No branches or pull requests

3 participants