fabric8io / docker-maven-plugin

Maven plugin for running and creating Docker images
https://dmp.fabric8.io
Apache License 2.0
1.88k stars 642 forks source link

RUN Command Support in docker-maven-plugin #1312

Open gkulkarni2020 opened 4 years ago

gkulkarni2020 commented 4 years ago

I have been using Dockerfile for my project with a sample code like given below.

RUN groupadd syslog && apt-get update && apt-get -q install -y curl logrotate iproute2

I would like to convert this to pom.xml so that other micro-services can inherit it.

I surely cannot add this under build tag as I cannot and don't want this to get executed at the build time, I rather want this to set up logrotate in the container when the container starts up.

I tried adding few run commands, but that did not work. I am trying to understand which XML tag needs to be used for making sure my container RUNs the command on start up?

rohanKanojia commented 4 years ago

have you checked out RunImageConfiguration in docs? Here is an example:

https://github.com/fabric8io/docker-maven-plugin/blob/96683f408eb4c5d78220b74aa747e3b581d08058/samples/data-jolokia/pom.xml#L98-L120

rhuss commented 4 years ago

I have been using Dockerfile for my project with a sample code like given below.

RUN groupadd syslog && apt-get update && apt-get -q install -y curl logrotate iproute2

Actually, everything in the Dockerfile is running during build time in order to prepare the container image. So I don't really understand your use case here. In your example logrotate is installed during docker build, not docker run (everything within a Dockerfile is executed during build time).

Said that you can provide an entrypoint or command in the run configuration which is executed when a container is started (otherwise the default from the image is used). Use entrypoint or cmd as described in https://dmp.fabric8.io/#start-configuration for executing code during startup (but this code must obviously already be contained within the container image).