How to build an image with specific dependency like deep learning environment?

what Do I Want To Do

I need to build an environment for deep learning. It would need dependencies like CUDA and cuDNN, and a high version compiler that is not default installed on the system like GCC.

The problem is that there is no existing image that exactly matches my need. I have to build it myself, and when I try to install GCC 7.5.0 via compiling source code on the nvidia/cuda image, It changed some settings and makes nvcc command unrecognized. This is just one step among all things I have to do to build an image, and it had already caused some ugly problems.

So what is the right way to do that ? Is there anyone who can provide some advice? Anything helpful would be appreciated!

System Environment on My Machine

  1. Docker engine and nvidia-docker has already installed
  2. Nvidia driver installed correctly for RTX 2080 Ti GPU
  3. the host operating system is centos 7

Docker Image Environment I Need

  1. centos 7 with CUDA and cuDNN
  2. python3.6 or higher
  3. GCC 7.5.0 or higher
  4. Anaconda (optional)

If I pull a base image and install all the dependencies one by one and commit this container in the end, I may pull this off, but this will end up with a huge image and some environment errors I am not willing to take.

So, Please tell me what I should do if you know something about it. and English is not my mother language so I make some mistakes that makes you confused, feel free to ask for details.

Thank you!