Install other software during docker image build

Hi,

I am able to build my own docker image by updating inventory file entries, but having issues when I tried to install following tools by adding these entries to awx/blob/devel/installer/roles/image_build/templates/Dockerfile.j2 file.

RUN dnf install -y jq
RUN dnf install -y wget
RUN dnf install -y gcc

Added these entries in different sections of the file and still no luck. I see other tools in “Install runtime requirements” and other sections, so not sure why the resulted awx-web image/container doesn’t have these installed. I don’t see any errors either during install process.

Also commented to run as root and that too didn’t work as I still see the user as ‘awx’ when I got shell into the awx-web container in my Kubernetes environment.

Any clues will be appreciated.

Thanks

Hi Cnu,

Where exactly have you tried adding these entries? it seems for some of them you must have a specific flag set like build_dev in https://github.com/ansible/awx/blob/devel/installer/roles/image_build/templates/Dockerfile.j2#L93.

I’ve tried a different route creating my own docker image by using docker directly without the installer.

For example create a docker file that will look like this:

Dockerfile:

FROM ansible/awx:14.1.0

USER root

RUN dnf install -y jq
RUN dnf install -y wget
RUN dnf install -y gcc

Build the image and push it to a registry :


docker build --tag my_awx:14.1.0_myversion --file Dockerfile .
docker tag my_awx:14.1.0_myversion myprivate.registry.com/awx:14.1.0_myversion
docker push myprivate.registry.com/awx:14.1.0_myversion

You then need to update the ansible installer to pull that image instead of the public one.

Hope that helps.

Be aware that there are TWO docker containers built by that Dockerfile! The first one is used to build python packages for use by the second. Somewhere around line 100 or so you will see a second “FROM” line. That’s the start of the build for the container that is actually pushed. Below that are a series of COPY commands pulling the venv and some other things from the first container.

Right, there are 2 FROM lines. I tried adding below statements under and outside as well after the 2nd ‘FROM’ image build.

RUN dnf install -y jq
RUN dnf install -y wget

I will check again, if not, will try your route mentioned above. I was trying to build by adding few extra tools to the main Dockerfile template but it doesn’t appear to be working.

Thanks

I do see above commands in the Dockerfile generated from the template but don’t see jq or wget utilities when I run ‘which jq’ and ‘which wget’.

I don’t think even which is going to work but, i remember gcc is part of the default dockerfile which is required to compile the code. Is there any specific error you are getting while building it. For me, it works simply by adding RUN commands in Dockerfile.j2.

Good to know that it’s working for you. I do see which command working for other software that’s in Install section. I don’t see any error or warning messages, the image building fails if I mention‘net stat’ command since it’s not in the yum or dnf repo.
Other than that I have not seen anything.
I will try to build another image manually by using the generated Dockefile and see if it works.

Thanks

Not sure if the issue is related to below Anisble task in https://github.com/ansible/awx/blob/devel/installer/roles/image_build/tasks/main.yml or docker_image Ansible module as I manually built a awx-web image with the same Dockerfile that’s used by docker_image module and I do see jq, nano, wget, and lsof installed there when I ran docker exec commands. The tools are there in ‘yum list installed’ list as well.

  • name: Build base awx image
    docker_image:
    build:
    path: “{{ docker_base_path }}”
    dockerfile: Dockerfile
    pull: false
    args:
    http_proxy: “{{ http_proxy | default(‘’) }}”
    https_proxy: “{{ https_proxy | default(‘’) }}”
    no_proxy: “{{ no_proxy | default(‘’) }}”
    name: “{{ awx_image }}”
    tag: “{{ awx_version }}”
    source: ‘build’
    force_source: true
    delegate_to: localhost

I will keep trying different options to make it work.

I gave up on building my own image as our corporate network has so many restrictions to install pip, npm and other open source packages.
@ Nicolas G, I have created my own image by adding jq, wget off of base AWX image and pushed to our private registry.
What changes need to be made to Anisble playbook or inventory fiiles to use that image instead of the docker hub public AWX image?

Thanks