Db2

 View Only
  • 1.  Building own db in docker container

    Posted Mon July 08, 2019 10:13 AM

    I would like to know the best way to build and run a container based on the ibmcom/db2 image, using a db restore from my existing db. 

    I have been successfully running a docker container based on the now gone express-c base image.
    Using the old image I could copy my db restore files and restore them inside the container as part of my build process.

    Since the express-c base image is no longer available, I have been trying to get to the same level of functionality using the currently available developer-c base image from docker hub

    Trying  to reuse my Dockerfile did not work as it now appears that DB2 takes ages to start and initialize. Therefore by the time I try to restore my own DBs on it, the db2inst user is not initialized. 

    I have followed the  Build Your Own section with no success: 

    Build Your Own

    You can use the Db2 container as a base to build your own custom container. Customizations may include additional setup scripts to execute after Db2 setup has completed, different license activation keys, additional OS packages installed, etc.

    To build your own, create a new Dockerfile and specify the desired Db2 base in the FROM line in the Dockerfile. The following example builds a simple container with Db2 as a base and copy a custom script into the /var/customdirectory. Any script copied into the /var/custom will be automatically executed after main Db2 setup has completed.

    FROM ibmcom/db2
    RUN mkdir /var/custom COPY createschema.sh /var/custom
    RUN chmod a+x /var/custom/createschema.sh

    The custom script is copied to the container. When run the container it tries to execute it but runs into permission issues. I am working through those now but I am not sure I am going the right way about this.  I still have to wait for the container to go through all the db2 initialization after running it. This used to be instantaneous on the express-c container.  

    Ideally I would like to see a working example, as the documentation on this is a bit flaky.

    Alternatively a bit more on how can I migrate my old container, based on the express-c image, to the new developer-c image. 



    ------------------------------
    Nikola N
    ------------------------------

    #Db2


  • 2.  RE: Building own db in docker container

    IBM Champion
    Posted Tue July 09, 2019 08:56 AM
    I did a series on Docker on my DiscoverDb2 Youtube channel - check out the playlist. Ep 16 may be too simple for your needs, but I believe Ep 17 is where you need to start. If you want to make your own dockerfile, watch 25 and 26. There is also a thread on this message board started by Rachel Miles that worked through a few problems she had which were ultimately documented on a blog.

    However, the way I would handle this is to get the Docker image up and running and you can mount/map a local directory on your machine to the docker image. Something like "docker run ..... -v /Desktop/Docker:/DOCKER". This will create a "DOCKER" filesystem in your image that maps to a desktop folder named docker. Put your backup in that folder and restore into your image.

    ------------------------------
    Michael Krafick
    ------------------------------