r/learnprogramming • • Apr 05 '22

Name one programming/comp sci concept you never understood and if you understand it, try to explain it to them

Name a programming concept such as virtual functions, pointers, certain algorithms, etc that you always had a hard time understanding and why.

Someone else who reads yours and does understand it, try to explain it to them to help them learn

1.6k Upvotes

738 comments sorted by

View all comments

Show parent comments

10

u/tzaeru Apr 05 '22

Consider a typical web application. It runs on a particular server. That server needs particular software to support the application.

Let's say your application needs Python version 3.6 and Postgres version 10.

You can manually install those on the server, but you would have to do that again for each server where you run your application.

Containerizing an application is a way of bundling the dependencies together. Instead of running your application on a server that already has the required components installed, you run your application as a Docker container which already has the required dependencies. So the server you host your application on doesn't need to know about Python or Postgres; It only needs to know about Docker. Docker takes care of all the dependencies required by your application.

This also makes it easier for you to run multiple applications with incompatible dependency requirements. Perhaps you have another application that requires Python 3.7 and Postgres 11. You could install those on the same server, but you would need to run the Postgres instance in a separate port and you may run into trouble with where Python3 points to. But if this application is also bundled in a Docker image, it doesn't matter - you just run that Docker image and again it takes care of the dependencies.

3

u/Gamithon24 Apr 05 '22

Does this mean dependencies aren't shared between Dockers. Meaning the same dependency can be installed on the same machine multiple times?

3

u/MrSloppyPants Apr 05 '22

Yes, but that's exactly what you want. If three apps all share a dependency on Postgres and then one of the apps needs to update it, the other 2 apps can have unintended side effects. By keeping things containerized, you isolate an app package from anyone else altering it or its dependencies

0

u/[deleted] Apr 05 '22

[deleted]

2

u/door_of_doom Apr 05 '22

It could be, but the real question to ask is "What do you want to achieve by doing that, and is that the best way to achieve it?"

A Docker container can run a game, but that is unlikely to be the best way to run a game.

1

u/tzaeru Apr 05 '22

In principle yes, but typically games statically bundle everything they need into a single package. Using actual containerization tech would probably just add unneeded complexity.

0

u/[deleted] Apr 05 '22

[deleted]

1

u/tzaeru Apr 05 '22

You could create e.g. a Docker image that includes cmake and then compiles and runs your application. Or it can include a pre-compiled version of your game.

But if the idea is to share this to players, it would be more convenient to simply build the game and statically link all the libraries the game needs.