hello welcome to another how to code
well YouTube tutorial my name is Peter
Fisher and this is the second part of
the docker image docker container set of
tutorials in this tutorial I'm going to
focus on how we can change and
manipulate a docker image once we have
the image downloaded to the machine in
the previous tutorial in the intro
tutorial I had a discussion on what the
difference is between a docker image and
what the difference is between a
container and the things that define the
two as well as a brief tutorial I
suppose a demonstration of how to pull
down an image and how to run them as
containers or run containers from the
images now I highly recommend you check
that video out the previous one because
it will give you some insight and some
better knowledge for this video also
I've got a docker machines tutorial that
I recommend you you watch too if you
haven't already done so I'll put links
to those in the description and the
YouTube cards up here as I go along but
today we're just going to focus on how
we can manipulate these images once we
have them so I'm gonna ensure that I'm
in the right machine so that's just you
block a machine active and this should
return the how to code well machine
which it does and if we did docker
images we shouldn't have anything here
and if we did docker PS - a we shouldn't
have anything there so you can see I've
got nothing up my sleeve so let's just
clear this down and what I'm going to do
is docker Paul and we're just gonna get
the you burn to the latest Ubuntu image
so this is this step is exactly what we
did in the previous video obviously I
had more explanation as to what I was
doing but we'll just wait until this
gets installed okay so if we did docker
images we can get the image ID alright
so what we need to do is create a
container
this image first before you know in
order to manipulate this image we must
get a container then we create this
container and get into it using a bash
shell then we install some bits and
pieces and then what we need to do is
save those bits and pieces to the image
so we can use it again so the first
thing we do is docker run and - mighty
we've got the image ID here and we're
gonna go in as bin
whoops bin bash so this again will bin
bash this will take me into a shell
which it does and what I can do is do an
apt-get update so that's going to update
the sources and I'm going to install if
I just do a clear I'm gonna install apps
get install and install NPM and p.m. cuz
this is something I use quite frequently
so if we go yes so this is actually
creating changes to the image okay so
this is creating changes to the image on
this docker machine and as this is
running through I would like to just
explain that there are things called
docker files now a docker file is what
what is used to actually create the
images from scratch I will go into those
in more detail in future videos and how
to create daka files and so forth but
the point I want to make is that it's
it's what I'm doing now is on I'm I've
kind of change I'm changing the image
without changing a docker file which in
some cases is okay especially from
committing it back to a registry but
it's always good if you want to start
from scratch to do these changes to have
the the end the apt-get install NPM
command within the docker file as well
so then you can put that into source
control and other developers can use it
but anyway I take your s so let's do NP
n minus V and we can see here we've got
three point five point two
that's fine and I'm just going to exit
out of this container okay so obviously
if I did docker images if I was to
remove this image and then they were
pulled from Ubuntu again I won't have
the NPM because this is something that
I've added myself so what I need to do
is commit this image and I'm committing
it to to my local how to code well
machine so what I do is do docker commit
in fact actually I need to do docker PS
- because you know I said before that
container is a snapshot of an image so
we need to do docker commit - no we
don't docker commit and then the come
the container ID so it's that one there
and we need to give it a name as well so
I'm going to do Ubuntu Ubuntu and I'm
just going to put - and p.m. - 10 p.m.
so what that is going to do after I
press ENTER is it's actually going to
create another image or a snapshot of
that container with NPM in there and if
I was working against a private or a
public public docker registry in which I
could login to I could then do a docker
push and push this or docker tag tag it
and then push it up so if I now did
docker images we can see that we have a
third image here Ubuntu - NPM so that
was the first one that we got the latest
that we got and then this is the one
that we have literally just created so
let's do a docker PS - a I'm just gonna
clear the screen docker PS - a and we've
got so we've got that container that we
were just in I'm gonna do a docker RM
and remove it
because what I want to do is do a docker
images and I want to do a docker run -
IT and I'm going to use I'm gonna use
this image the new image that we've got
and I'm going to run that and actually
what I'm going to do is just run NPM -
fee okay so that will print out the
version of NPM from the container so if
I did that
we should get 3.5 points here which we
do now if I was to do that against the
previous image the image that we first
got from the public registry the Ubuntu
repository so find it NPM if I ran lap
against here we will get an error and
we'll get an error because NPM isn't
installed in that image it is in this
image but not in that image so if I did
that then we get an error a pretty nasty
one and basically that means that the
executable file cannot be found in the
path so I'm just gonna clear that down
and you took off PS - a and likewise if
I was to let's just do a docker RM there
are other ways of actually getting into
these containers using docker Exe but I
will show that to you later on I'm gonna
just kill that and also kill that one
like so so I talked a PS - I think there
go back to docker images so if we were
to do a docker run - I T to the original
image ID so that's the original Ubuntu
image and then if I was to just run that
as bin bash and did a NPM - V we can see
that is tomorrow cannot be found so I'm
going to exit out of you and I'm going
to now jump into being bash in this
image
and paste that in undo an NPM - feat and
we can see it is there so this is how
you create your images where you update
your images and you commit them and like
I said if you have if you were connected
or logged into a registry you could then
do a tag and a push to push this stuff
up it's very important to keep
committing as you go and also like I
said it's very important to have a
docker file that you can update as you
go - just to keep a record of what
you've done I'm going to leave it there
even though there's a lot more to to
this subject I'll probably pick that up
again in in the following tutorials but
if you've got any questions then please
do let me know put them in the comment
section below
like a video if you found it helpful and
please do share it around subscribe to
get the next set of tutorials and also
the web chats that I do every week so
thanks again for watching and I shall
see you again soon bye