Skip to content

Instantly share code, notes, and snippets.

@jatin-lab49
Last active September 3, 2020 20:51
Show Gist options
  • Save jatin-lab49/2d045f553425efd88d1f48e9196ac039 to your computer and use it in GitHub Desktop.
Save jatin-lab49/2d045f553425efd88d1f48e9196ac039 to your computer and use it in GitHub Desktop.
TIL-Lab49/Unzip jar file without unzip command inside a docker image

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment