openstack cli in a docker container

If you need to access your openstack cluster but there is no option to install packages on a jumpbox host that can access the cluster (lack of internet access or privileges) an alternative is to build locally a docker image that includes openstack CLI utility. Assumption is that the jumpbox host has docker installed and user can load docker images and run docker containers.

Firstly prepare a Dockerfile (based off python docker official images in this example):

FROM python:3.9.10-slim
 
RUN /usr/local/bin/python -m pip install --upgrade pip
RUN pip3 install python-openstackclient
RUN pip3 install python-heatclient`
 
#stackrc file used to access openstack cluster
ARG STACKRC
RUN echo "$STACRC" >> /root/.bashrc
 
#Overwrite entrypoint
ENTRYPOINT ["/bin/bash"]

Build docker image and provide as an argument path to stackrc file that includes details on how to access the cluster (endpoint, passwords etc).

docker build -t ospclient -f dockerfile-ospclient --build-arg STACKRC="$(cat /home/user/stackrc)" .

After build is finished save docker image to tarball:

docker save ospclient > ospclient.tar

Copy tarball to a destination machine which can access openstack cluster and load docker image:

docker load < ospclient.tar

Run the container – you’ll and try listing e.g. servers

docker run -it ospclient
 
#inside the container
(overcloud) root@aed39c7006cd:/# openstack server list