If you’ve followed along in my other network posts about bridge and the rest of the default networks, you may have noticed that I keep spinning up CentOS containers. This is well and good for demos and instructional purposes but you might have also noticed that they don’t really do anything. I mean they exist, but that isn’t why you run things in your environment. You don’t have a bunch of server OSes spun up doing nothing, right? RIGHT?
Well, we hope not anyway. Ideally your server actually does something like hosts an app, database, or webserver. In this post we are going to explore some aspects of bridge networking and get a little more into the underpinnings of Docker. And in order do that, hey we need a container that actually does something!
Again we are going to keep things simple with a default installation and bridge functionality. I’ll write some details at the end about MACVLAN and host networking to hopefully bring all of this full circle.
The easiest thing for me to do for this demo is to spin up an nginx container. This is a pretty simple container that just has an nginx webserver inside it. Now if you were doing this on a new non-containery box you’d likely be doing a yum install nginx and maybe some configuration. We certainly can do that on our install – take the CentOS container and do a yum install on it – but that isn’t a very efficient way to run things. I’ll write some more on this later but you’ll end up with some really big containers. In general you aren’t installing big packages on big base containers like you are with VMs.
Instead we are simply going to pull down the nginx container and run it. To do that, we use the same commands that we did for the CentOS bit:
[root@dockernet2 ~]# docker pull nginx Using default tag: latest latest: Pulling from library/nginx Digest: sha256:788fa27763db6d69ad3444e8ba72f947df9e7e163bad7c1f5614f8fd27a311c3 Status: Image is up to date for nginx:latest [root@dockernet2 ~]# docker image list REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest b8efb18f159b 8 days ago 107MB centos latest 36540f359ca3 4 weeks ago 193MB
So in this case I already had the nginx “latest” container available so it just skipped the download. You can see the size difference between that and CentOS. You might be saying to yourself, “self, what is the big deal about 100MB?” Well I would put it more at “half the size” personally (it has a little more oomph put that way), but imagine running tons and tons of these containers on multiple hosts in multiple locations for multiple purposes. The size will add up in a hurry.
Now, I’m going to run an nginx container using the default parameters which means it will attach to the bridge network. I’m going to background it so it doesn’t take up my shell and I’m not bothering with the “it” flag because an interactive terminal won’t do much for me anyway.
[root@dockernet2 ~]# docker run -d nginx 4d5d54275890a27971a694b2f32dd7bb954744a10a856c6676b6b4f4f03b1902 [root@dockernet2 ~]# docker container list CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4d5d54275890 nginx "nginx -g 'daemon ..." 6 seconds ago Up 4 seconds 80/tcp goofy_stallman
Again if you’ve followed the other blog posts you’ll see the ports section here actually has information in it instead of being blank.