How to limit RAM for Docker image

Hi all,
i want to limit the RAM of a ubuntu image to 2GB.is there any command to execute it and do my job easy for me. and second thing is that i want to save new packages installed in docker and it to be saved permanently…