Docker CMD or RUN using JIB build
Asked Answered
C

1

7

I need to create a custom image based on Ubuntu that contains software that I need to install using apt. For example:

sudo apt-get install pcscd 
sudo apt-get install pcsc-tools # same as pcsc-lite   

# For OMNIKEY for driver Then unpack the file and run the installer:
cd /home/cccam/ifdokccid_lnx_x64-3.7.0/ 
chmod 755 install
sudo ./install

And I also want the software to run under OpenJDK 1.8 64 bit which I will also install. The point is I need to run commands like these. How can I do this with JIB? Is there a way to get JIB to use a Docker File? Is there any way to pass a script of commands like this into JIB?

Cadenza answered 4/11, 2019 at 3:47 Comment(0)
K
12

Jib does not use Dockerfile (and it works even without Docker installed); the way Jib builds an image is fundamentally different from how the Docker CLI builds an image using Dockerfile (reproducible vs. non-reproducible, declarative vs. imperative, Docker and Dockerfile-less build vs. requiring Docker daemon and client, requiring root-privilege vs. not). Basically, Jib doesn't "run" Dockerfile directives, particularly the ones like RUN that executes something; Jib doesn't provide/include a Docker runtime (that is one of the points of Jib).

For installing complex software packages like OpenJDK, the best option (for now) is to prepare a custom base image that comes with all those packages pre-installed and have Jib use that image. Note recent Jib versions can specify a local Docker daemon image or a tarball as a base image (in addition to a remote registry image).

If you just need to install a small number of binaries, you can copy arbitrary files with the extraDirectories feature (Maven / Gradle). Here is an example that installs a Stackdriver Debugger Java agent using the feature.

Just in case, you can configure Jib to run arbitrary ENTRYPOINT or CMD, or include custom script files (using the extraDirectories feature) and run them at runtime, but I don't really think you are asking this capability. I believe your goal is to install extra software packages at build time.

Kevenkeverian answered 4/11, 2019 at 15:45 Comment(3)
Hi! So I have installed everything as you suggested in the base image. Now I do need to know how to RUN the service that I installed before the Springboot app starts up. When I add command to kubernetes pod it just runs the command and exits the container. So I am looking for what does jib add to startup the Springboot application?Cadenza
@AverageBear set the correct entrypoint to run your service (in this case, the Spring Boot app). But Jib sets the correct entrypoint, so you should need to configure it. If the container ran and exit right away, I think your application has some issue. Double-check if the image you built runs without an issue locally by docker run <your image name>.Kevenkeverian
@AverageBear I saw you posted another question for this (https://mcmap.net/q/1444757/-docker-cmd-or-run-using-jib-build/1701388). I've left an answer there.Kevenkeverian

© 2022 - 2025 — McMap. All rights reserved.