So, you successfully have your containers and you have started to be able to run containers to do stuff. Brilliant. So let us drop into those containers and run something new. You are probably half way there with your understanding, maybe we could say that you have just opened the door on containers, well, you are just about to step in an see how big the room is! Containers give you great, little, isolated machines that you can do with as you please and then throw away.
View Docker Images
So when you have pulled some images down to your machine you are going to want to see what they are and what the Image ID is. You are going to need to know that. Find out what images you have locally installed by running "docker images".
➜ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php 7.0 1f12c608053f 2 hours ago 361 MB
php 7.1 1130c01d10e1 2 hours ago 362.8 MB
node alpine 164dad592f49 9 days ago 55.3 MB
node latest 89cd8193c9a1 2 weeks ago 655.5 MB
Choose an image that you want to run and remember that IMAGE ID.
Interactively Running Docker Images
One of the great things about isolation is that you can have multiple versions of the same software all on your machine at the same time. Anyone who has worked in software for some time will understand the term dependency hell where you have dependencies on different software to run your software. Most common web development now requires some combinations of PHP, Python, NodeJS and Ruby to run different builds and deployments and having all of these installed, with the correct version, is a nightmare. Not to mention running all of the "npm install", "composer install" and "gem install" commands.
So wouldn't it be great to be able to have multiple versions of the software you want, inside containers, with no chance of them crossing over and messing up your machine? Docker gives you that.
➜ docker run -it 1130c01d10e1 /bin/bash
So, what have we just done? Well you remember the image id from earlier? You should be able to see that we have just run a new container using the php:7.1 image and gone into an interactive terminal command (on /bin/bash). If we dissect the command, we have:
- docker ==> You already know docker
- run ==> Run a command in a new container
- -it ==> Interactive terminal
- 1130c01d10e1 ==> The image id of the docker image you want to run
- /bin/bash ==> The terminal prompt/command you want to run from
What Can We Do Now?
Good question? Well, realistically we can start to do a lot of things. All of those command line tools that you want to install, you can do it? Running Windows and therefore you don't have a machine that has a good command line, now you do!
Some extra tags:
- -d ==> Detached. Run the container without dropping to the terminal.
- --name ==> give your image a specific name