Everytime I open the project in my remote containers, it takes some time to build the image.
Once you create the image once, the next time it should be almost instantaneous to connect to the remote container. However, if in between remote containers sessions your code has been modified (ie. you added or removed a line of code or you switched to a different branch), the image will be rebuilt.
Here a scenario in which your container image will not be rebuilt (timer saver):
You open VSCode, then switch to the remote container. You do some changes to your code, push the changes to a branch called feature and then move back to the local directory. In the local directory, you make a pull to get the latest changes of your feature branch.
The next day, you start working again on your feature branch so you switch from the local directory to the remote container.
In this scenario, the container image is not rebuilt, since the last image built for the remote container was built with the code from feature branch.
Here a scenario in which your container image will be rebuilt (will spend a little more time):
This time, imagine that before switching to your local branch, you realize that another club member has always worked on the branch feature and added some important changes to it. You want to be up to date with the latest version of the code so you run the git pull command before switching to the remote branch.
In this scenario, the container image will be rebuilt, since the last image built for the remote container was built for a previous version of the feature branch.
To avoid this from happening, one thing you can easily do is to pull the changes when you are inside the remote container instead of in your local directory. Remember, when switching from the local directory to the remote container, even the smallest change (ie. you realize there was a typo inside a comment for the and you correct it. Let’s say the typo was in the word proc_imaeg_processing. You correct it by switching the “e” and the “g” inside the word image) will cause your container to be rebuilt entirely! So try to keep that in mind in other to save a few minutes, this can add up for a lot in the long run.