Merging Docker Images

I found the need to merge 2 Docker images
(e.g. intersystems/iris-community:2020.2.0.199.0 + my home grown NodeJS Image).
I found some advice on the Web but no real convincing solution.


It is basically not merging the images but merging (manually) the generating Dockefiles.
No problem with my own docker image (with sudo, editor, npm, nodejs,   and root access ...)
But where could I get the Dockerfie that generated my IRIS distribution?

I managed to have a workaround and a usable working Docker image.
Bur this was handcrafted by try & error.  Not what I intended!

Suggestions are very welcome

 

  • 30
  • 0
  • 338
  • 7

Replies

docker compose?

Unless you need inprocess communication (you don't for NodeJS native API) you can just refer from one container to another.

OK! for access to the Native API it works fine. And I used that.
my intention was to have just 1 container to run instead of  2.

BTW: Would file access work from 1 container to the other over a commonly used external volume ?  (haven't tried yet)

There is no such way as merging two images. If you need only one image, the only way is to make a new one, which would combine the main from both images. So, you should choose which one is going to be as a base image, I would suggest it supposed to be IRIS. Then you can create install inside nodejs, and your node application. The issue is here you may face is that you will have only one init process after that. While I suppose you have to have started IRIS and NodeJS application at the moment. You can add a script which will run in a background nodejs application, and pass it to iris-main through CMD directive in conjunction with '-a', '-b', '-c' or '-t' parameter
So, it can be something like this

FROM intersystestems/iris:2020.2.0.204.0

USER root 

# script which will run nodejs application in background
COPY app-entrypoint.sh /

# copy your nodejs application
COPY ./nodeapp /opt/nodeapp

# install nodejs v10, and node_modules
RUN apt-get -y update && \
 DEBIAN_FRONTEND=noninteractive apt-get -y install curl --no-install-recommends && \
 curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
 DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs --no-install-recommends && \
 rm -rf /var/lib/apt/lists/* && \
 chmod +x /app-entrypoint && \
 cd /opt/nodeapp && \
 npm install

USER ${ISC_PACKAGE_MGRUSER}

# say to start your nodejs application after IRIS start
CMD ["-a", "/node-entrypoint.sh"]

Thank you @Dmitriy Maslennikov !
That confirms that I didn't miss a "magic merge feature".
My way wasn't that complete (I stripped the context example)  
Ending up with base to work with.  So I "just" have to elaborate my Dockefile.

My NodeJS has to start after IRIS anyhow, so iris-main could be great:
But to visualize that it isn't just a fake it ist should run -it what iris runs -d detached.
An additional manual start is no problem.

@Eduard Lebedyuk  you inspired me to try the shared volume  yes

I keep you posted
 

In the context of complex docker images, one more feature worth to be mentioned. It is multi-stage builds. It makes sense when you have to do some build something in your project, but you don't need any immediate files, for instance, source code, or any temporary files. Or some part of your app written in the compilable language, like go, and you can't compile it let's say it on IRIS image. You can first run go image, build it, and then build your final image base on IRIS where you just copy the result from the first stage.

In case of IRIS, you can build this way, deployable code. Just build your application from source code, deploy, and copy the result to the fresh image, and it will keep you from the error of letting your source code go with the final image.

Yeah!  So you produce a deployed mode image.  

yes
 

@Eduard Lebedyuk  , @Dmitriy Maslennikov 
I tried it and it works:   - v $(pwd):/mnt/share/

I set it for both containers and they read/write to it as any other user would do.

My consequence: 

  • the "Install container" fills all required data
  • the "production container" consumes it.  It's similar as data transfer from 1 process to the other over IRISTEMP  

and I have no need for a merge as in my initial case.