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

2

u/[deleted] Apr 05 '22

What is deployment? I could never understand the purpose of Docker.

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.

3

u/HecknChonker Apr 05 '22

When you write code you need it to run somewhere so users can access it. This used to mean buying a computer that sits in your office and runs your code, but eventually large companies set up data centers with many computers and they let other people run their code there.

But different apps need different configurations. And sometimes you want to run many copies of the same app, and when you make a change you want to update all of them with that same change. Pushing out those changes is called a deployment, as you deploy code to a bunch of servers.

Docker helps in automating this process. You can set up your application to build a docker image, and that image can run in a data center that someone else manages. The docker image contains an operating system, your code, and any required dependencies your code needs.

2

u/[deleted] Apr 05 '22

When you program something in your machine, it has some configuration right? Operational system, language version, frameworks and libraries version, etc.

That might work fine, but it's useless if other people can't access the software you wrote. So you need to "upload" that program to a server. However, you need to make sure this server also has all the same versions and tools that are needed.

In a very simplified way, Docker is a set of rules that define those settings. So it says what's the OS running the application, if there are frameworks and libraries, what version is running there? What's the database?

With that, you can have a team of developers using the same tools and versions for everything, making sure the application will work in any machine following those rules.