46

In this docker beginner video its explained, that different stacks may depend on different libraries and dependencies and that this can be handled with Docker.

However, I don't get what the difference should be between a library and a dependency. As I see it, a library is a collection of code/packages and a dependency is a library that the database/webserver/tool depends on.

So is there any difference? Or is saying "a database relies on specific libraries and dependencies" the same as "a database relies on specific libraries" ?

Glorfindel
  • 3,167
Adam
  • 587

5 Answers5

106

Libraries and dependencies are like persons and relatives: One is just an entity (something), the other is a relational entity.

I am a person. My niece is also a person. But to her, I'm a relative. You cannot simply be a relative by nature; you're always a relative of someone else.

Similarly, a code library becomes a dependency only when another project uses it, and then it's a dependency of that project and not of another. Even though a code library is invented specifically for other projects to use, it's not a dependency until this actually happens.

Kilian Foth
  • 110,899
41

If an application uses a library, the application has a dependency on that library.

Libraries are not the only type of dependency an application can have. Software can also depend on:

  • configuration files
  • device drivers
  • databases
  • etc.

So 'dependency vs library' is like 'fruit vs apple'. Libraries are one type of dependency, just as apples are one type of fruit.

Rik D
  • 4,975
12

Dependency

In Docker image you have dependencies on different types and versions of:

  • underlying OS (CentOS, Debian, Windows, ...)
  • database (Mongo, Postgresql, ElasticSearch, ...)
  • tools, and programs (curl, git, awk, wget, ...)
  • servers (ngnx, tomcat, ...)
  • platforms (java, nodejs, python...)
  • frameworks (Spring, Angular, Play, .Net Core, Django ...)
  • libraries

Libraries

A compiled code that has functionality readily available to be consumed in a program. Its manually defined by the programmer or its required by the framework itself.

Now in context of Docker a lot of libraries will be installed by all of the above mentioned components like tools, platforms..

Reasoning

In the Docker Tutorial for Beginners video I would define libraries and OS as subset of dependencies . Libraries are one part of dependencies that will be needed to build a Docker image and mainly they will be managed by the different dependencies itself.

One should say: "database relies on specific libraries and other dependencies" (like also @Rick D mentioned in the comment).

RenatoIvancic
  • 229
  • 1
  • 4
11

A library is a specific piece of software that is intended to be consumed by another program. Typically, the library will address a specific/group of specific issues (although they can sometimes grow to a point where it's hard to identify what the original issue is/was). A library can be either internal or from a third party. Typically, a library is also something that is not executable, but requires the consumption.

A dependency, like the earlier answer suggested, is a relationship between two pieces of code. The first code calls out to the second code to either perform an action or return some information. The key part, though, is that the first code no longer has any control over how the action or information is implemented. This can be either a library, framework, database source, api call, or even a separate function. If you have a single function program, and decide to break out part of that into a second function that gets called, your main function now has a dependency on the second one. You might still have control over the new function, but your main function no longer has any control over how the work is implemented.

0

Suppose you built a simple program A to get number. And you are using a library B to get random number to program A. Let's say you are creating a program C which uses program A which in turn depends upon library B. So now program A is your library and library B becomes your dependency.