dockerfile - multiple binaries in a docker container based on scratch -


i have spec container requires 2 binaries executed 1 after other. prefer inherit scratch image container no larger sum of 2 executables. obvious way accomplish inherit alpine or other small os i'd prefer scratch. also, cmd, run , exec commands in dockerfile seems require shell , scratch not option. building 2 containers , docker swarm interesting not answer.

i'm not entirely sure question here, here few ideas.

first, correct run requires shell, doesn't sound need that. have 2 binaries, we'll call file1 , file2, , need copy image:

from scratch copy file1 /file1 copy file2 /file2 

if wanted run single executable, life simple. cmd not require shell, add:

cmd ["/file1"] 

using json version of cmd means binary executed without shell.

while running single command easy, fact want run 2 different commands in sequence means need something handle workflow. easiest solution shell, because can run:

cmd /file1;/file2 

but if don't want shell, need write third binary handles executing first command, waiting complete, executing second. make entire dockerfile like:

from scratch copy file1 /file1 copy file2 /file2 copy file3 /file3 cmd ["/file3"] 

unless planning on deploying in unusually space-constrained environment, time better spent using alpine image or similar.

update

since came in comments:

using -e or --env-file not impose special requirements on container. example, can produce container contains /usr/bin/env command (and necessary shared libraries); complete image source looks like:

dockerfile lib64/libc.so.6 lib64/ld-linux-x86-64.so.2 usr/bin/env 

and dockerfile looks like:

from scratch copy . / entrypoint ["/usr/bin/env"] 

and file bar.env contains:

bar=somevalue 

assuming build container named "testenv", can run:

docker run -e foo=bar --env-file bar.env testenv 

and see:

path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin hostname=f8f43505a272 bar=somevalue foo=bar home=/root 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -