Adding border to the body will show you the issue:
<body style="margin: 0;border:2px solid red;">
<div id="header" style="height: 50px;width: 100%;position: sticky;top: 0px;background-color: rgb(33, 150, 243);">
<div>header contents</div>
<div>header contents</div>
</div>
<div id="container" style="position: absolute; top: 50px; left: 0px; width: 100%;">
<div style="height: 1000px;">
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
</div>
</div>
</body>
As you can see the height of the body is defined by the sticky element thus there is no sticky behavior. if you remove the positon:absolute
you will make the element part of the flow thus the body height will increase and you have a sticky behavior
<body style="margin: 0;border:2px solid red;">
<div id="header" style="height: 50px;width: 100%;position: sticky;top: 0px;background-color: rgb(33, 150, 243);">
<div>header contents</div>
<div>header contents</div>
</div>
<div id="container" style=" top: 50px; left: 0px; width: 100%;">
<div style="height: 1000px;">
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
</div>
</div>
</body>
The issue isn't the position:absolute
element but the height of the containing block (parent container) of the sticky element. This one need to be big enough (at least bigger than the sticky element) to have a sticky behavior.
Increasing the body height and keeping the absolute element will also fix this:
<body style="margin: 0;border:2px solid red;height:200px;">
<div id="header" style="height: 50px;width: 100%;position: sticky;top: 0px;background-color: rgb(33, 150, 243);">
<div>header contents</div>
<div>header contents</div>
</div>
<div id="container" style="position: absolute; top: 50px; left: 0px; width: 100%;">
<div style="height: 1000px;">
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
<div>some contents</div>
<br>
</div>
</div>
</body>
Another related answer where you can find more examples of how sticky works: Why element with position:sticky doesn't stick to the bottom of parent?