1

I'm trying to create docker image extended from a base image with some tweaks. Adding files works fine, running commands however doesn't save. I've been looking at the Dockerfile of the image I'm extending but I'm none the wiser.

My Dockerfile:

FROM openmicroscopy/apacheds:latest

ADD *.ldif /etc/ldifs/
ADD addall.sh /etc/ldifs/addall.sh

RUN /bin/bash /etc/ldifs/addall.sh

the bash script:

#!/bin/bash/

/run.sh &
sleep 20

for file in /etc/ldifs/*.ldif
do
    ldapadd -v -h localhost:10389 -c -x -D uid=admin,ou=system -w secret -f "$file"
done

Would anyone happen to know how I can add items to the ldap and save it as an image?

Gelunox
  • 772
  • 1
  • 5
  • 23

1 Answers1

0

This wont work, while building the image, the Server is not started. You could create bash script startet when the container is started, where you run the import.

entrypoint.sh

# check if ldap import already done

# if not - import
for file in /etc/ldifs/*.ldif
do
    ldapadd -v -h localhost:10389 -c -x -D uid=admin,ou=system -w secret -f "$file"
done

# if yes - don't import
opHASnoNAME
  • 20,224
  • 26
  • 98
  • 143
  • 1
    Presumably the OP wants to create an image pre-loaded with these entries - in which cases the ldap server can be started while building the image, before adding the ldif files to it, instead of adding the entries each time the container is started. – nos Oct 10 '18 at 07:43
  • the server is started temporarily with `/run.sh &` which is the entry point of the container I'm extending – Gelunox Oct 10 '18 at 07:45
  • 1
    Not sure if this is possible? I would check while starting the container if the import is already done, if not import... like migrations on DBs – opHASnoNAME Oct 10 '18 at 07:45
  • turns out it is indeed easier to just check at startup if the import has been done already. – Gelunox Oct 10 '18 at 08:20