How to copy depth buffer to a texture

We know we can copy color buffer to a texture using “glTexSubImage2D()”,but is it possible to copy depth buffer to a texture?

Try to put GL_DEPTH_COMPONENT in format glTexSubImage2D param.

Init the texture with:
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowX, shadowY, 0, GL_DEPTH_COMPONENT, GL_BYTE, 0);

Copy the zBuffer of the framebuffer to Texture with:
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowX, shadowY);

Or do you mean the a depth buffer from system memory?