I created docker image for DB2. if i run the container and then started, but i can’t start the DB2instance…getting error “shared memory allocated”. for that error i got solution run container with “docker run -P --privileged=true -it db2-express-c” it working.
But, i want to run this command “docker run -P --privileged=true -it db2-express-c” from inside the dockerfile
cons:- I want run container from inside the dockerfile
There is no way for you to specify in a Dockerfile that an image must be run in privileged mode, you would need to fish for that information and crash out.
Do you know why db2 requires privileged mode to work?
yes… it required to operate “sysctl” command’s on host. other wise, it will read mode only…
1.) is there any possibility while building the image, at any point of time can we start that image(with Image ID)?
Hi Joe,
I tried with “RUN” but it failed to start the image on the process of building image… in more detailed
1.) i need to start a image to a container… at the end point of image building in a process.
Here, while building docker image with dockerfile i need to start that same image before build complete( by using image ID$ )… task to do is when running command “docker build -t db2 .” the vale have to take from host machine…
now at step 9 is
docker run -i -t `docker images | grep -v "REPOSITORY" | head -1 | awk '{print $3}'` /bin/bash
The general philosophy is this - “one app per container”. You will see this idea manifested in many places, for example, multiple ENTRYPOINT or CMD lines in a Dockerfile will be ignored and only the last entry will be accepted.
So I would recommend you change your design to accommodate this idea - “one app per container”.
But if you still want to run more than one app in a container, one idea I can think of, is to list them in a shell script and make that as an ENTRYPOINT.
HI Joe,
it’s not container…it’s image( earlier replay)
I tried with giving the shell script in ENTRYPOINT…But the Error is “SQL1042C An unexpected system error occurred.” for the db2.( that error due to un-authorized to start service)
{Docker command not working inside the container’s (at ENTRYPOINT)}
why am asking is, for DB2 need to run the image in “–privileged=true” other wise it can’t start the instances.
For building Sonarqube and jira… web services need the DB. to config and install the application.
trying for automachine. eg:- building image from jenkins using Dockerfile, in case JIRA
2.1)after completing of DB2 login to DB2 image then create the instances, later committing the container.
2.2) Now one more file with hard coded value’s file to build the JIRA…
Same instances not used for multiple application. so, if same Dockerfile run’s in different Docker engine. the output will be error’s right?
The more I think about your issue here, the more I think that it is a simple USER issue, meaning the ibmcom/db2express-c image might not have been setup to run as root.
In the Dockerfile, do this:
FROM ibmcom/db2express-c
…
…
USER root
…
…
I am unable to test this, as ibmcom/db2express-c is not available now.
Hi Joe,
Sorry for later reply… i was hospitalized
I have tried with that option earlier it self , but the issue… when you specifying in Dockerfile
(Ex:- From db2-express:1 )
that image not stating with “privileged”. and also specifyed the script to start the instance
Step 0 : FROM testdb2
—> e52568fc5c39
Step 1 : ADD db2.sh /tmp/db2.sh
—> b8a25ea9b523
Removing intermediate container cf6837013b0e
Step 2 : RUN chmod +x /tmp/db2.sh && /tmp/db2.sh
—> Running in 416f3fdd556b
SQL1220N The database manager failed to allocate shared memory.
INFO[0063] The command [/bin/sh -c chmod +x /tmp/db2.sh && /tmp/db2.sh] returned a non-zero code: 2
And one thing am running with User root
Is there any option to build with “privileged”… that will help me to resolve this issue…
“privileged” mode is a run time option for Docker Containers.
I think the best solution for you is to debug the Dockerfile step by step.
For example, I would recommend, building a container till the point you run the db2.sh command, then bash into that container and try that command. Make sure that, that works. Then proceed.
I believe that anything that can be done manually consistently, can be automated, to the most part!
What I meant here is that, go as far as you can go with the steps in Dockerfile and when it fails, create a Container with until the previous step, then bash into that Container and run the command and see what is failing and why it is failing. Fix that and move forward with automation. If it does not work with manual steps, it will not work with automation.