YouTube/@code/Dev Container Features & Lifecycle Hooks
Notes
- example feature: having the azure CLI
az executable available in the shell
Video
- 00:00 today we're taking a look at def container features and life cycle hooks as a refresher a def container essentially packages up your Project's development environment using something called the development container specification which will enrich your container with metadata and content necessary to enable development from inside of the container Now features allow us to add run times tools and Library sard devic containers while life cycle hooks ensure that certain actions or tasks are executed at a specific time in the life cycle of a Dev container all this put together ensures a consistent and reproducible development environment from any tool that supports the specification and for a list of those
- 00:46 tools be sure to check out the link in the description in the later half of this video we'll also run through how to add a feature to an existing Dev container configuration so you can get Hands-On with all these Concepts all right let's Dive Right In let's now take a look at a feature I'll select one from the community index of features on containers. deev I'll have the link in the description I'm going to search for git I've been working with the git lfs one recently so we'll open that one as an example and we can see that each feature lives inside of its own folder and contains at least two files the def container Das feature. Json file and the install.sh let's click on the dev
- 01:27 container D feature. Json one and this file is meant to contain all the metadata for the feature so we see have an ID a version documentation URL and a couple of other things I did want to make note of this here the post create command this is actually a life cycle hook which will take a look a little deeper in a bit but we can see that this specific key value here is telling us that we need to execute this script on post create command let's go back and take a look at the install data s and the install sh script uh essentially is sort of like an installation entry point script and this might set up dependencies environment variables or perform other set of tasks required for your development environment within the
- 02:13 container one of the key strengths to Dev container features is versatility they are built to be compatible across a wide range of Base images although some features may be specific to an operating system or uh distribution by specifying the desired feature and your def container configuration file uh they're going to automatically be included during the build process and we're going to take a look at how to do this in just a little bit and while you're at it don't forget to like And subscribe life cycle hooks are essentially commands that are executed at a specific predetermined point in your DEA containers life cycle and this strategic execution allows for a very high degree of automation ensuring that tasks are
- 03:03 executed exactly when they need to be executed and without the need of manual intervention let's take a look at the available life cycle hooks oncreate command initializes the container with necessary configurations right after it's created update content command refreshes or updates the container's content following the oncreate command life cycle hook ensuring that any changes in the source are applied and the postcreate command applies final setup configuration specific to the user once the container is ready to use after the update content command post start command ensures that certain tasks are performed every time the container is restarted maintaining the necessary environment or settings and then post
- 03:49 attach command facilitates the execution of tasks each time a tool is successfully connected to the container enhancing the Tool's integration or functionality within the container through these life cycle hooks Dev container features automate the setup process from initial creation to daily operations ensuring that your development environment is consistent efficient and tailored to your project needs let's now take a look at how to add a feature to an existing Dev container configuration you will need to make sure you have vs code installed and the def containers extension and I'll link a video in the description for you to go and set that up now in my example I have a python project we see a python
- 04:32 file here and then I also have a def container folder and a def container. Json file which is the configuration file for my Dev container right now in my terminal if I type in uh for example AZ which is the Azure CLI it's not going to work cuz it's not installed so we can actually do control shift p to invoke the command pallet and type in configure container features uh which is part of the def containers extension and then once I click this this is going to allow me to scroll through available features that I can install and I'm going to type in Azure CLI and I'm going to click on this one then I'm going to hit okay now we can choose to keep defaults or configure options I'm just going to keep
- 05:12 defaults and of course these options will be different depending on the feature itself now I've added that and we can see that in my dive container. jsone file this feature section now has the Azure CLI listed inside of it now what I can do is rebuild my container we see that vs code prompted me configuration files changed the container might need to be rebuilt to apply the changes so I'm going to hit rebuild and let's give vs code a moment to rebuild the dev container for us all right and as we mentioned before once you do specify the features in your def container. Json configuration they're going to be part of the build process of your container so now if I type in a we can see that I no longer get an error
- 05:58 and it's giving me actually the h menu for the Azure CLI and congrats you've officially added a feature to your Dev container configuration and that's it we've covered def container features and life cycle Hooks and we've even added a feature to an existing Dev container configuration I'd encourage you to check out the links in the description for more resources and try to see how you can add features to your own Dev container configurations with all that being said don't forget to like And subscribe and stay tuned for more awesome vs code videos