Yes, this behavior stems from the need to stay safe in the wild. When a dog considers you as its alpha, they want to remain as close to you as possible. For this reason, dogs can sleep on their bed right next to you. Although they make sure that their alpha gets enough space.