Join Arthur Ulfeldt for an in-depth discussion in this video The Docker flow: Images to containers, part of Learning Docker.
- [Instructor] Now that we've got Docker installed and talked a little bit about what Docker is, let's talk about what Docker does. The Docker flow the fundamental concept, in Docker it all begins with an image. An image is every file that makes up just enough of the operating system to do what you need to do. Traditionally you'd install a whole operating system with everything for each application you do. With Docker you pair it way down so that you have a little container with just enough of the operating system to do what you need to do, and you can have lots and lots of these efficiently on a computer.
Let's take a look at that. So let's take a look at Docker images. Amazingly creatively, the command to look into your Docker images is Docker images. It's a little bit squished, let me stretch that out for us, there we go. So here we have where the image came from, the repository, a tag is a version number. The repository for the image is where it came from.
In this case it was named ubuntu, this is the example we use in the installation movies. Tag is the version of it, in this case it's tag latest. And then there's image ID which is the internal Docker representation of this image. So you could always refer to this image by the combination of its name and its tag, ubuntu colon latest in any Docker command or you can refer to it by its number. It's useful to be able to refer to them by number because sometimes they don't have a name, they don't have to.
But if they do have a name it's a little more convenient to use it. Now what good is an image if not to do something with it? The Docker run command takes an image and turns it into a living running container with a process in it that's doing something, hopefully something useful, but at least something. So let's take a look at running an image to make a container. So now that I've got my image, I want to actually run something in it so I'm gonna use the ever conveniently named Docker run, and I'm gonna put this couple of flags in here, TI stands for terminal interactive.
It just causes it to have a full terminal within the image so that you can run the shell and get things like tab completion and formatting to work correctly. When you're running commands by typing on a keyboard inside an image, this is a very useful flag to put in. Most of the other times you don't need it, TI for terminal interactive. Now we need to say which image we'd like to run this thing in, ubuntu with the latest tag. What would we like to do? Well, since I'm gonna by typing on this keyboard I'm just gonna run the bash shell in my image.
Alright, I'm in my image. If I look around I'm in an ubuntu environment. Let's take a look at the standard place to see what distribution I'm using. Ah, I'm using ubuntu 1604 here. To exit this you can type exit or you can just press control D. So now we have a running image. I'm gonna run that image again and bring up another terminal so we can take a look at it from the outside.
There we are. I've got my ubuntu container running in the terminal on the left here, so on the right I'm gonna use the Docker PS command to take a look at the running images. So let's just run Docker PS. Now on my screen it looks a little squished here, and I prefer to look at things vertically so just for my personal preference I have defined a format string which will print them out vertically instead of horizontally.
This is completely optional, you don't have to use it but some people will find it more convenient. We'll take a look at that format string in a moment. For now let's take a look at what we got here. So our container, the running container has an ID which is different than the image ID that was used to run it from. These are not the same thing. Images have one set of IDs, containers have their own sets of IDs. They don't overlap and there's no place in Docker where you can interchange image and container IDs.
At least not that I know of. So that's the ID of the container. Here we see the image that it was made from, the command that's running in it and when it was created, its status and its name. Since I didn't specify a name when I started this container, Docker helpfully made me a nice creative one. So that format string I mentioned, this is just a convenience for my personal preference. It looks like this. You might see things differently in the terminal on your computer if you just run Docker PS without the dash dash format.
You're getting the same information, you're just getting it laid out horizontally instead of vertically. And you can freely play with format strings to format the output of most Docker commands in almost any way. It's very flexible, even if it doesn't look very pretty. Alright, now we have a running container. So this next part is sort of the important crux of what makes Docker different from virtual machines or running things on a real computer.
When you're inside a container you start from an image and that image is fixed, it doesn't change. When I make a container from an image, I don't change the image. So in my container over here which I made from the ubuntu image, ubuntu latest image I made this container, I'm gonna create a file. So we're at the root of the file system and I'm gonna make a big file. The touch command just makes empty blank files. Make a file called my file here in big letters.
If I do LS, right there, there's my file here. If I go over to this other terminal, if I start up another container from the same image that I made this one from, so I'm just gonna run that same command again. Docker run dash TI to make it pretty ubuntu latest bash, so I've started from the same place and made a new container. Do an LS, I do not see that file.
See, my file here shows up on this side, it's in this container but it's not in another container made from the same image. And if I exit this container and I start it up again, the file is not there. Files go into containers, but that doesn't put them back into the image that the container came from. They stay in that container.
Released
8/27/2018- Installing Docker on Mac, Windows, and Linux
- Understanding the Docker flow
- Running processes in containers
- Managing, networking, and linking containers
- Working with Docker images, volumes, and registries
- Building Dockerfiles
- Managing networking and namespaces with Docker
- Building entire systems with Docker
Share this video
Embed this video
Video: The Docker flow: Images to containers