>> Hey, everyone. I'm Brigit.
Welcome back to our series on
Using remote containers in Visual Studio Code.
In this video, I'm going to show
you how to add software to an existing container.
Right now, our Dev container has Python set up,
which is really useful.
But what if we want to add another software to it?
What if our company uses Node.js a lot?
That would be really helpful,
but I'm not really sure how I would approach that.
What my first options is to go ahead and
install software through the integrated terminal,
so I could run a command in the terminal on VS Code.
Most container images are based on Debian or Ubuntu,
where the apt or apt-get command is used to install new packages.
However, if I make changes to
my dev container and I go ahead and need to rebuild it,
all of the changes that I went ahead and
installed through the integrated terminal would be lost.
I would need to go ahead and install any new packages
that I installed there every time that I rebuilt my container,
which feels like it's not necessarily
the most efficient or best practice to use.
One way to avoid this problem is to use the post create command,
which is going to be a property in our
devcontainer.json which is a file
that Burke went over in the previous video.
However, the really most robust and efficient way
to install new software is in our Dockerfile.
That's what we're going to take a look at in this video.
Here I'm in my Python application,
in my Python dev container.
What I'm going to do is open up the Dockerfile.
I'll go over here and in my.devcontainer folder,
I'll click on the Dockerfile.
At the bottom, I'm going to go ahead and add some code.
That way I can add Node.js into my dev container.
Again, the best way to do that or to add really any
new software setup persists is to do that in the Dockerfile.
To go ahead and explain a little bit on the code
that we went ahead and added into the Dockerfile,
let's break down the code that we went ahead and added here.
We can see that we have a run command here.
Essentially a run command is going to
go ahead and create a new layer.
Now layers are going to be how
the container knows what has changed
and what in the container needs to be updated when you rebuild it.
As a best practice,
you should try to keep related logic together
in the same run statement or in the same run command,
that way you don't create unnecessary layers.
Now, the backslashes that we have here at the end of lines
are needed if we have multi-line run commands.
The double ampersands that we have here
are how you can add a new command to your run command.
Then finally, the dash y that we have here
ensures that this command here,
this apt-get, doesn't prompt
you to confirm that you want to finish the installation.
For instance, when we have this installation here,
if we didn't have the dash y,
there wouldn't be anything indicating if we
were saying yes or no to complete the installation.
Instead, the container build would fail or it get hung up there.
You want to make sure that when we're installing something,
we include that dash y.
Now that we have this code here, this front command,
go ahead and install node in our current Python Dev container.
I'm going to go ahead and save this when you hit "Control+S".
Now, I can run the command.
I can do this by opening the command palette
or by using the remove indicator in
the bottom left that can say remove containers, rebuild container.
I want to do that whenever I make changes to
my containers configuration.
Here we are.
We are rebuilding our container
so that way the changes can take effect.
Now we can see that our Window has
reloaded so now our container is rebuilding.
We can see here in the bottom right that this notification
tells us that it is building our image.
If we wanted to, we could
learn some more information about what's going on,
we can click "Show log"
which would show us details in the terminal.
For instance, I could select that.
It would give me some more information about what's going on.
Now, let's go ahead and check to make sure that node installed
successfully and let's check what version installed as well.
I'm going to say node--version.
There we go. We can see that we now
have node successfully installed
within our Dev container and it is node version 14,
which is the version that we decided to put in our Dockerfile.
We did successfully add a new text stack or
new software to our Dev container, which is awesome.
Thanks for joining me today to take a look at
installing additional software into our Dev containers.
In the next video in the series,
it's actually going to be the final video and we're going
to wrap up what we covered and check out
some additional resources so you can continue your learning
into the world of remote containers and Visual Studio Code.
[MUSIC]