Hi, getting this error when tried to add the exten...
# general
r
Hi, getting this error when tried to add the extension class to my docker container where I am running the wiremock image. I want to use the extensions that i have created inside the container.
Copy code
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: <http://unable.to|unable.to> start container process: exec: "wiremock": executable
Gracefully stopping... (press Ctrl+C again to force)
file not found in $PATH: unknown
 wiremock-extensions %
t
Can you share how you’re starting your container and where you’re placing your extensions?
r
Sure
docker run -d --name wiremock -v $(pwd)/custom-extension.jar:/home/wiremock/extensions/custom-extension.jar -p 8080:8680 wiremock/wiremock:3.10.0 --extensions custon-response-transformer
t
The
--extensions
parameter needs to refer to the fully-qualified Java classname of the extension, rather than its string name
r
Yep tried with that as well, it gave me the same error, let me share it
docker run -d --name wiremock -y $(pwd)/custom-extension.jar:/home/wiremock/extensions/custom-extension.jar 8080:8080 wiremock/wiremock:3.0.0 --extensions com.example.CustomResponseTransformer
I tried with adding the META-INF folder as well to the jar but gave me the same error
t
Your port mapping is the wrong way around also, try
-p 8680:8080
Does it work if you remove the extension parameter and the volume mount?
r
Yes then it works good
t
And does your extension have a service definition in it, because if it does you need to remove the extension parameter anyway
r
Yep it does have, let me try if it is working with different port number
docker run -d -p 8680:8886 -v $(pwd)/src/test/mock/__files:/opt/wiremock/__files -v $(pwd)/src/tes t/mock/mappings:/opt/wiremock/mappings -v $(pwd)/src/main/java/com.example:/opt/wiremock/extensions --name wiremoc <wiremock_image> --extensions com.example.CustomResponseTransformer
I tried the above and getting the error
t
Can you paste the full shell contents - command plus the full output and error?
r
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "--extensions": executable file not found in $PATH: Unknown.
Hey @Tom here is the screenshot, this time I have just created the jar of the directory in which my extension class was written and used it. I have added class name in with the --extensions parameter . Have been stuck on this since a day wonder what I am doing wrong!!
t
Do you have a class named
org.example.CustomResponseTransformer
in the JAR file you’ve put there?
Also looks like you’ve mounted the extension to the wrong place. It should be under
/var/wiremock/extensions
in the container.
r
Yes my jar has the class. Let me try with the correct mounting.
A bit of improvement. I am getting the below error, looks like I have created the JAR using java 17 and the wiremock container that I am uses Java 11 and not able to read the class
t
Can you build the JAR with Java 11?
r
Yep trying it out
Hey thanks @Tom it worked.
But when I am trying it out in my work laptop it is giving me below error again - docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "--extensions" : executable file not found in $PATH: unknown. Is it to do something with the java version?
I found out that my wiremock image is custom one and does not has the wiremock folder inside the var folder. Is it mandatory to use the /var/wiremock directory to use extensions?
t
If you use the official image, then /var/wiremock/extensions gets added to the classpath by default, so this is where you’d need to mount your extension JARs. Note that /var/wiremock is not where everything is, just the extensions.
r
Sorry to ask again. So /var/wiremock directory is not important for the extensions to work right? I mean the custom image that I got for my use case has no wiremock directory inside var. If yes what can I do in such case?
t
I suggest checking the the command line in your image that starts WireMock. The extensions directory (or at least the individual JARs) need to be on the classpath at startup (usually the
-cp
parameter). I suggest checking what that’s set to in your image then mounting your extension JAR wherever that points to,
r
Error: Main method not found in class com.github.tomakehurst.wiremock.standalone.WireMockServerRunner, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
t
That’s the old main class. You need
wiremock.Run
instead, so you’ll need to update your docker image command to this
r
Hey @Tom i did the following changes after you suggestions 1. Changed the start.sh file in my custom image and added the custom extension jar there with the -cp. 2. In my custom image mounted the extension jar where my start.sh is pointing to. 3. Verified that the jar has all the META-INF files. Conclusion - i am not getting the response as per the extensions added i.e the extensions are making no difference. Looks like wiremock is not able to pick it. And also when I run ps aux | grep java in my container I can see both the wiremock standalone jar and the extension jar is added to the class path. Is there anything else that I need to check and debug?
t
When WireMock starts it lists the loaded extensions as one of the config attributes dumped to the console. Is your extension appearing in that list?
r
So @Tom, In our custom image, we cannot see the start up logs as they are supressed, is there anywhere else we can see if extensions are linked to the wiremock instance?
t
No, you’ll need to temporarily enable stdout logging if you want to see this. Alternatively you can start the container with the shell as a command instead of WireMock, then run WireMock from within the shell so that you see the output.
r
Hi @Tom We are trying to test our custom extension jar locally using wiremock standalone jar. We mentioned the classname in meta-inf/services but when we start the server, it's not showing in the list of extensions.
Hey @Tom thanks a lot for helping me out. The issue is resolved.
t
Excellent, glad to hear it!