• Learn Enough Docker to be Useful
  • By Jeff Hale
  • The Nuggets translation Project
  • Permanent link to this article: github.com/xitu/gold-m…
  • Translator: EmilyQiRabbit
  • Proofread by: MarchYuanx, TokenJan

Learning and application of Docker

Part ONE: Basic concepts

Containers are useful for software development and data storage security, reproducibility, and scalability. Their rise is one of the most important parts of today’s tech trend.

Docker is a platform for developing, deploying, and running applications in containers. In fact, Docker is synonymous with container. If you are, or aspire to be, a software developer or data scientist, Docker is a must-learn.

Don’t worry about falling behind — this article will help you understand the basic concepts of Docker — and then you can apply it from there.

In the next five articles in this series, I will focus on Docker terminology, Dockerfiles, Docker images, Docker commands, and data storage. Part two is now online:

  • Learning and Using Docker (2) : Those Docker terms you need to know

By the end of this series (there will be some exercises), you should have a basic understanding of Docker and be able to use it 😃!

The Docker metaphor

First, let’s start with an analogy to Docker.

Google’s definition of metaphor is exactly what we need to know:

To represent or symbolize something else, especially something abstract.

Metaphors can help us learn new things. For example, comparing it to a container entity can help us quickly understand the nature of virtual containers.

Container

Just like a plastic box entity, the characteristics of a Docker container include:

  1. Contain things — after all, things are either inside or outside the container.

  2. Portable – It can be used on on-premise devices, shared devices, or cloud services such as AWS. It’s kind of like the box you put your gadgets in when you moved house as a kid.

  3. Provide clear interfaces — the physical box will have an opening that allows us to open it and put and take things out. Similarly, Docker containers have mechanisms to communicate with the outside world. It has an open port that allows it to interact with the outside world through a browser. You can configure it for data interaction from the command line.

  4. Remote access support – you can buy another empty plastic box from Amazon when you need it. Amazon gets plastic boxes from manufacturers, who can make thousands of them from a single mold. For Docker containers, remote login preserves an image, which is like a box mold. If you need another container, you can make one from this image.

Unlike virtual Docker containers, you have to pay to buy new plastic boxes from Amazon, and you don’t get a copy of what you put in them. Sorry 💸.

Live an instance of the

The second way you can think about a Docker container is as an instance of a living thing. An instance is something that exists in some form. It’s not just code. It brings things to life. Like any living creature, this instance will eventually die — meaning the container will be closed.

A Docker container is the living form of a Docker image.

software

In addition to the box metaphor and the living instance metaphor, you can also think of the Docker container as a software program. After all, it is still software at heart. Basically, a container is a set of instructions that can compute bits.

When a Docker container is running, it usually has programs running inside it. The application performs operations inside the container so that the application can perform certain functions.

For example, the web page you’re reading right now might have been sent to you by code inside a Docker container. Or it may read your voice commands and send them to Amazon Alexa, where your voice is decoded into other commands that are then used by programs in other containers.

With Docker, you can run multiple containers simultaneously on a single host. Like other software programs, Docker containers can be run, detected, stopped, and deleted.

concept

The virtual machine

Virtual machines are the forerunners of Docker containers. Virtual machines also decouple applications from their dependencies. However, Docker containers require fewer resources, are lighter and faster, so they are more advanced than virtual machines. You can read this article to learn more about the similarities and differences.

Docker mirror

I mentioned mirroring in the previous article. So what is a mirror image? I’m glad you asked! In the context of Docker, the term mirror has a completely different meaning than an actual photo.

The Docker image is more like a blueprint, a cookie mold, or a mold. An image is a master template that does not change and is used to produce multiple containers that are identical.

The image contains the Dockerfile, libraries, and application code to run, all bound together to form the image.

Dockerfile

A Dockerfile is a file that contains instructions for how a Docker builds an image.

The Dockerfile points to an underlying image that can be used to build the initial image layer. Widely used official base images include Python, Ubuntu, and Alpine.

Additional layers will be added on top of the underlying image layer according to the instructions in the Dockerfile. For example, a Dockerfile for a machine learning application will tell Docker to add NumPy, Pandas, and sciKit-learn to the middle layer.

Finally, a thin and writable layer will be added on top of all layers according to the Dockerfile code. (Thin actually means that the volume of this layer is very small, you understand that, right 😃? Because you understand the thin metaphor intuitively.)

I’ll explore Dockerfiles in more depth in other articles in this series.

Docker Container

The Docker image plus the command Docker run image_name will create a container from the image and start it.

The Container registry

If you want others to build containers with your image, you need to send the image to the container registry. Docker Hub is the largest and the default registry for people.

Alas! Too many bits and pieces. We put it all together, and we put it all together, and it’s like making a pizza.

The Docker practice

  • The recipe is a Dockerfile. It tells us what to do to make a good pizza.

  • The material is the Docker layer. Now you have the dough, sauce and cheese for your pizza.

Think of the combination of recipes and ingredients as an all-in-one pizza-making kit. This is the Docker image.

The recipe (Dockerfile) tells us how to do it. As follows:

  • Pizza dough is immutable, like a basic Ubuntu parent image. It is the bottom layer and will be built first.

  • And then we need to add some cheese. The second layer of pizza is like installing an external library — NumPy, for example.

  • And then you can add some basil. Basil is like code that you write in a file to run your application.

Ok, now let’s start cooking.

  • A pizza oven is like a Docker platform. You move the oven into your home so you can cook with it. Similarly, you install Docker on your computer so you can manipulate containers.

  • You turn the knob to get the oven going. The Docker Run Image_name directive is like your knob — it creates and gets the container working.

  • A good pizza is like a Docker container.

  • Eating pizza is like using your app.

Like pizza, creating apps in Docker takes work, but in the end you get great results. Enjoy it!

The end of the

The main content of this article is the conceptual framework. In the second part of this series, I’ll explain some of the terms you might see in the Docker ecosystem. Keep an eye on me so you don’t miss it.

Hopefully this overview will help you understand Docker better. I also hope it gives you an idea of the value of metaphors when it comes to understanding new technologies.

If you found this article helpful, please share it on your favorite social media so others can read and learn. 👏

I also write about Python, Docker, data science, and many more. If you’re interested, you can read more here and follow me on Medium. 😄

Thank you for taking the time to read!

If you find any mistakes in your translation or other areas that need to be improved, you are welcome to the Nuggets Translation Program to revise and PR your translation, and you can also get the corresponding reward points. The permanent link to this article at the beginning of this article is the MarkDown link to this article on GitHub.


The Nuggets Translation Project is a community that translates quality Internet technical articles from English sharing articles on nuggets. The content covers Android, iOS, front-end, back-end, blockchain, products, design, artificial intelligence and other fields. If you want to see more high-quality translation, please continue to pay attention to the Translation plan of Digging Gold, the official Weibo, Zhihu column.