Keycloak Docker image basic unix commands not available

Viewed 1895

I have setup my Keycloak identification server by running a .yml file that uses the docker image jboss/keycloak:9.0.0.

Now I want get inside the container and modify some files in order to make some testing.

Unfortunately, after I got inside the running container, I realized that some very basic UNIX commands like sudo or vi (and many many more) aren't found (as well as commands like apt-get or yum which I used to download command packages and failed).

According to this question, it seems that the underlying OS of the container (Redhat Universal Base Image) uses the command microdnf to manage software, but unfortunately when I tried to use this command to do any action I got the following message:

error: Failed to create: /var/cache/yum/metadata

Could you please propose any workaround for my case? I just need to use a text editor command like vi, and root privileges for my user (so commands like sudo, su, or chmod). Thanks in advance.

2 Answers

It looks like you are trying to use approach from non docker (old school) world in the docker world. That's not right. Usually, you don't have need to go to the container and edit any config file there - that change will be very likely lost (it depends on the container configuration). Containers are configured via environment variables or volumes usually.

Example how to use TLS certificates: Keycloak Docker HTTPS required

https://hub.docker.com/r/jboss/keycloak/ is also good starting point to check available environment variable, which may help you achieve what you need. For example PROXY_ADDRESS_FORWARDING=true enable option, when you can run Keycloak container behind a loadbalancer without you touching any config file.

I would say also adding own config files on the build is not the best option - you will have to maintain your own image. Just use volumes and "override" default config file(s) in the container with your own config file(s) from the host OS file system, e.g.:

-v /host-os-path/my-custom-standalone-ha.xml:/opt/jboss/keycloak/standalone/configuration/standalone-ha.xml

If you still, for some reason, want to exec in to the container try adding --user root to you docker exec command.

Just exec:ing in to the container without the --user will do so as user jboss, that user seems to have less privileges.

Related