PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] How to run a docker container from within java

 October 18, 2022     docker, docker-java, java, macos     No comments   

Issue

I want to run the following command from within a Java Eclipse Project:

docker container run -p 4000:5000 virtuprint:vp

where virtuprint:vp is an image. I installed the docker-java api from here https://github.com/docker-java/docker-java using all its dependencies via maven. I am using MacOS, I guess that's causing my trouble.

I already read the docs and wikis, and just did some test code to see if it's running (and of course it's not.)

DockerClient dockerClient = DockerClientBuilder.getInstance().build();

        List<Container> containers = dockerClient.listContainersCmd().exec();

        for(Container c: containers) {
            System.out.println(c.getId());
        }

So I just want to print the container-ID in short term. Long term I want to run multiple docker containers on demand from within my java application. But if I run the code I get:

java.lang.NoClassDefFoundError: Could not initialize class org.newsclub.net.unix.NativeUnixSocket

I guess it's because he is trying to find unix sockets on places they aren't, but I neither know where they are nor how to tell him where to find them.


Solution

Played with the dependencies, downgraded to version 3.0.14 and sticked closely to this guide: https://www.baeldung.com/docker-java-api

don't know why but now it works.



Answered By - Flontis
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing