Cannot use cudaMalloc in nvidia/cuda docker container

Hi,
I am new for cuda programming. When I use nvidia’s official cuda docker image, the cudaMalloc function can not work, it got error:named symbol not found. I checked the nvcc version and it looks fine. I already got stuck for two days, could anyone help me to solve this?

docker image: 12.1.1-devel-ubuntu20.04

nvcc version:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Mon_Apr__3_17:16:06_PDT_2023
Cuda compilation tools, release 12.1, V12.1.105
Build cuda_12.1.r12.1/compiler.32688072_0

My test code:
include
include <cuda_runtime.h>

int main() {
const int size = 100;
const int bytes = size * sizeof(int);
int d_a;
cudaError_t err = cudaMalloc((void
*)&d_a, bytes);
if (err != cudaSuccess) {
std::cerr << "Error in cudaMalloc: " << cudaGetErrorString(err) << std::endl;
return -1;
}
return 0;
}

The error I got:
Error in cudaMalloc: named symbol not found

That is incorrect code.

Please study nearly any CUDA sample code such as vectorAdd to learn how to properly allocate a pointer.

In the future, when posting code on these forums, please format it properly. One possible method is to use the </> button at the top of the edit window, after selecting your code.