Can you tell me whether commands with different functions in dockerfile should be written separately or after a RUN command?

  docker, question

For example, may I ask whether commands with different functions in dockerfile should be written separately or after a RUN command?
For example, when I create a new image based on Ubuntu, I usually update it first and then install some necessary commands. Then you have to install the software you need later. Is it better to write these commands after a RUN or separate several RUN commands? Thank you!

Another problem is how to make the image created by dockerfile smaller. I installed anaconda and several software to generate 6G images. . .

Try to use a RUN command, because each Docker command is a layer, and the basic image is smaller, such as small volume basic image such as alpine. For details, please refer to7-step Thin Docker Mirroring Hundreds of MB (Part 1)