While triaging a running docker container, I was trying to check if a jar file had the correct properties file inside it.
I found the jar file and when I ran the handy unzip
command, I got this error:
service@3f50ceae48d2:/tmp$ unzip micro-service.jar
bash: unzip: command not found
Now, usually I would just go ahead and apt-get install unzip
in a Ubuntu container like this. But I was not root,
so ran into another issue:
service@3f50ceae48d2:/tmp$ apt-get install unzip
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
Thankfully, I remembered the docker image already had Java, and the jar
utility has a command to unzip the jar itself!
A quick google got me to this page: https://docs.oracle.com/javase/tutorial/deployment/jar/unpack.html
TLDR: Unzip a jar file without the unzip command using:
service@3f50ceae48d2:/tmp$ jar xf micro-service.jar
BONUS: to bash into a docker container which has a defined entrypoint, use this:
docker run -it --entrypoint /bin/bash <image_name:image_tag>