In Firefox, the width of the img container isn't random. In fact it is the original width of the img (600px), CSS alone can't determine the rendered width when the image's height is based on a percentage.. What exactly do you want to achieve? if you really want to force it, use JS to determine the image width on page load.
function changeWidth() {
const container = document.querySelector('img-container');
const img = document.querySelector('img1');
container.style.width = img.clientWidth + 'px';
}
window.onload = changeWidth
windw.onresize = changeWidth