Docker CFLAGS march=native and illegal hardware instruction

I’ve recently hit an interesting issue involving Docker containers and compiled C code crashing code with illegal hardware instruction errors.

In a nutshell the Docker image was built on a server using Jenkins. It has been running fine until the underlying host orchestration software and physical hardware changed.

My solution has been to remove the build of the C code from the Dockerfile and instead put in inside a script which runs when the container starts.

For my use case this solution will work, however, it will require the C code to be compiled every time the Docker container runs.

Digging a little deeper, it appears that the underlying root issue may be the use of the CFLAGS march=native flag in the C code’s underlying Makefile.

A few posts on Stack Overflow (in particular, https://stackoverflow.com/questions/54039176/mtune-and-march-when-compiling-in-a-docker-image), suggest that removing this flag may make little difference to the run time of the compiled code. Which, again depending on the use case, may be a good option to try as well to resolve these problems.