We have the need to create a docker container that also has the db2 client installed. This container will also have some shell scripts that make use of the db2 client.
We take a base Cent OS image and then add db2 via a RUN command:
COPY db2rtcl_nr.rsp /db2install/
RUN cd /db2install && curl -o ibm_data_server_runtime_client_linuxx64_v11.1.tar.gz http://public_file_server.com/downloads/appTools/installs/db2/ibm_data_server_runtime_client_linuxx64_v11.1.tar.gz && \
tar -xvf ibm_data_server_runtime_client_linuxx64_v11.1.tar.gz && \
rm -f ibm_data_server_runtime_client_linuxx64_v11.1.tar.gz && \
rtcl/db2setup -u db2rtcl_nr.rsp -f sysreq && \
chown -R 1000:1000 /opt/ibm/db2/V11.1
ENV PATH="$PATH:/opt/ibm/db2/V11.1/bin"
The image builds ok with no errors.
However, when I try running and connecting to the container via interactive shell command:
docker run -it --entrypoint=/bin/bash db2Container
and try to invoke the db2 CLI with
db2
I get the error:
DB21018E A system error occurred. The command line processor could not continue processing.
Whats confusing is that if I immediately run a bash shell and then invoke the db2 CLI, it works:
bash
db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 11.1.0
You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 =>
Things I have tried to diagnose the issue:
When I 1st drop into the interactive shell session, I type
env > /tmp/env1.txtI then typebashand runenv > /tmp/env2.txtWhen Idiffthe files, they are virtually identical EXCEPT for the variable:SHLVL=2which I know is just indicating that the 2nd shell is a nested shellWhen I 1st drop into the interactive shell session, I type
set > /tmp/set1.txtI then typebashand runset > /tmp/set2.txtWhen Idiffthe files, they are virtually identical EXCEPT for theSHLVLvariable again
Why is the db2 CLI accessible after I bash in the container but not in the initial session when i have used docker run -it?
We are attempting to use this container as an executable container that has the db2 client in it to connect to external DB2 databases. We are NOT trying to run a db2 DB in a container.
What I am starting to find is that I might have an issue with how the entrypoint is defined in our Dockerfile. Using:
ENTRYPOINT cat /dev/null && /usr/bin/bash
the DB2 client is available when I run docker run -it ContainerName without having to immediately type bash
BUT it does not work when I try to run the container as an executable docker run ContainerName
The closest I have come to the solution is this modification to the Dockerfile:
ENTRYPOINT []
CMD ["/bin/bash"]
When I run the container as an executable docker run ContainerName db2 list command options it works however NOW if I docker run -it ContainerName I dont immediately have db2 commands available without typing bash once. This is still problematic since this container will have shell script in it that need to be able to run db2 commands