Search code examples
dockerdb2dockerfiledb2-express-c

DB2 in Docker results in DB21018E


I can't build a Docker image with DB2.

Dockerfile:

FROM ibmcom/db2express-c

EXPOSE 50000
CMD ["db2start"]

SHELL ["/bin/bash", "-c"]
RUN su - db2inst1 -c "db2 create db DMX"

Log:

Building image...
Step 1/5 : FROM ibmcom/db2express-c

 ---> 7aa154d9b73c


Step 2/5 : EXPOSE 50000

 ---> Using cache

 ---> 3172f8b3790b


Step 3/5 : CMD ["db2start"]

 ---> Using cache

 ---> f38e27452920


Step 4/5 : SHELL ["/bin/bash", "-c"]

 ---> Using cache

 ---> 1cef61dbf3c5


Step 5/5 : RUN su - db2inst1 -c "db2 create db DMX"

 ---> Running in 59b7a5d1c0ba


DB21018E  A system error occurred. The command line processor could not 
continue processing.

Error: ResponseItem.ErrorDetail[code=8,message=The command '/bin/bash -c su 
    - db2inst1 -c "db2 create db DMX"' returned a non-zero code: 8]

But if I execute su - db2inst1 -c "db2 create db DMX" manually it works:

MB-54:test mkadan$ docker exec -i -t db2 /bin/bash
[root@5cb934e6d434 /]# su - db2inst1 -c "db2 create db DMX"
DB20000I  The CREATE DATABASE command completed successfully.

Any hint what's the problem here?


Solution

  • The problem was indeed in bash environment not set up correctly. I resolved it by using the following RUN command:

    RUN su - db2inst1 -c "/bin/bash && db2start && db2 create db DMX"

    instead of the original one:

    RUN su - db2inst1 -c "db2 create db DMX"