84
u/sombriks Feb 23 '24
not gonna lie, perform a docker compose up -d and go home is satisfying. even better, docker stack deploy -c docker-compose.yml and see the swarm do his thing.
14
u/Remarkable_Win7320 Feb 23 '24
What does this one do? Deploy onto some sort of a cluster?
31
u/argylekey Feb 23 '24
yes. You can use a docker-compose.yml file to spin up replications in a swarm.
Various VPSs can be setup to be added to a swarm, and deployments can be put behind a load balancer. In theory docker swarm manages several replicas of your applications, and puts them on whichever machine has the resources for it. i.e. you have 4 machines setup, and you want 3 replicas of some API, swarm will figure out which of the 4 machines to put stuff on.
It's like Kubernetes lite(or at least that is how I think about it).
11
u/Plasmatica Feb 23 '24
Even if you're not scaling over multiple machines Swarm can be useful for zero downtime deployments on a single machine.
6
7
u/Far-Mathematician122 Feb 23 '24
How long does it take for a beginner that has no experience in docker to learn docker compose and swarm to make it production ready ?
14
u/argylekey Feb 23 '24
That is entirely personal.
For someone who is well versed in linux, and has setup cloud servers a lot? Maybe a weekend? Production ready(Certs/SSL/proper firewall rules/load balancer setups/etc) maybe 2-4 weeks depending on how fast you are?
For someone who is not used to deploying to cloud, longer.
In general my opinion, I'd say for my personal projects, swarm makes sense. I'm not sure if there are managed swarm options, generally its roll your own(AFAIK). For real world production/mission critical services pay for a managed Kubernetes cluster and learn Helm.
I'm OK at setting up VPSs, and I can tell you it isn't easy to get right. I mess it up a lot. I wish I was good at it. Working on it.
2
u/StaticCharacter Feb 23 '24
I've been exploring caprover recently and it looks like they have lots of options for deploying docker swarm mostly managed :) might be worth looking into
3
u/sombriks Feb 23 '24
you can go through the official guides, they are a very gentle introduction https://docs.docker.com/get-started/overview/
1
u/Redicus Feb 25 '24
I am learning backend to become full-stack. Can you help me point to a learning source for the things you mentioned here?
Docker-compose Replications in a swarm. VPS in a swarm. Deployments behind a load balancer.
2
u/argylekey Feb 27 '24
https://docs.docker.com/engine/swarm/stack-deploy/
Sorry, I've been thinking about your question a lot of what documentation I actually like for this stuff. I think these two pages are what I actually reference the most when I'm building something out.
1
u/Redicus Feb 28 '24
Hey, thanks a lot for showing care. I feel that this resource is better than the previous one.
1
u/argylekey Feb 26 '24
https://doc.traefik.io/traefik/v1.7/user-guide/swarm-mode/
That’s a good place to start. Learning Traefik is a whole thing in itself. There are lots of other options, but this is my preference.
4
u/BlazingThunder30 Feb 23 '24
If you're going that route, doing
helm installand seeing Kubernetes go is even better! And I even have it automatically assigning DNS subdomains to services if I want-5
u/serendipity7777 Feb 24 '24
Is docker more scalable than lambda functions?
9
u/pwmcintyre Feb 24 '24
I'm not sure this question makes sense
Docker is for orchestration
AWS Lambda is a FaaS
It's a bit like asking if apples have more zest than oranges
0
u/Hour-Ladder-8330 Feb 25 '24
Op's question makes perfect sense. They asked if docker swarm is better for horizontal (and vertical) scaling compared to aws lambda which does similar thing at infra level EXCEPT lambda instance gets shut down by AWS once finished and no further requests.
So, horizontal scaling part is same in lambda and docker swarm and its a legit question if you only care about horizontal scaling
70
u/maximusprime2328 Feb 23 '24 edited Feb 23 '24
These aren't really comparable.
Docker ensures that you have a consistent environment. Local environments on dev teams are very inconsistent. This person is running this version of x software on their computer. Another person is running this version. So you use Docker, more commonly just referred to as containers, upstream in testing, staging and production to make sure that the environments are the same. Locally you can use Docker to ensure that your environment is consistent with environments upstream. It gets rid of the "well it works on my computer" excuse.
PM2 is just a process manager.
-36
u/alex-weej Feb 23 '24
It doesn't though because there's no guarantee of reproducibility in the build. Nix does a much better job.
16
u/minicrit_ Feb 23 '24
what? the whole point of an image is you set up the same exact environment lol
3
u/VanDieDorp Feb 23 '24
well a lot of copy pasters do
alpine:latestand even if you do aoraclelinux:8.9if you build the image today, and build it in 6 months the user env would have been updated with patched binaries, etc.So that is why you have image registries, to share builds that is exact.
1
u/The_Fresser Feb 24 '24
Yes if you build with different tags you get different images.
Your already built and tagged image does not change even if you use latest, only if you rebuild it and overwrite the tag.
Also don't use latest besides for testing/dev. Pin your versions dammit.
1
u/Hour-Ladder-8330 Feb 25 '24
Unless you have ECR or something similar internally where you host docker images by title with your configuration and pull the exact same image from ECR on all dev's machine. This will always work in future
-14
u/alex-weej Feb 23 '24
OK, but you described Docker as a whole, not OCI images. Much of Docker usage is grabbing a Dockerfile or Docker Compose config and "building it" on the fly with no reproducibility.
10
u/oze4 Feb 23 '24
Have you ever experienced the "it doesn't work on my machine" problem with Docker? I'm not being sarcastic, I'm being genuine, because from what I have seen Docker has eliminated this.
The point is I'm not building/testing on my local machine, but to a standardized environment/container so anything local to my machine doesn't interfere.
2
u/Ruben_NL Feb 23 '24
I can give you one example, but it's very specific, and not many people will have that issue:
DIfferent processor architectures. A image build for x86/64 doesn't run on ARM64 (and if it runs, it's very slow because emulation).
0
u/Internal_Pride1853 Feb 23 '24
I did. It was related to running .sh files and on Macs and Ubuntu it was running well but it didn't work on Windows. Turned out to be an issue with line endings and changing git auto clrf config and redownloading the repo fixed the issue. The fix was not needed on Ubuntu / Macs :)
5
u/oze4 Feb 23 '24
Did those bash scripts run inside the container? Or were they used in the process to create the Docker container?
This is a good one, though. Thanks for sharing.
1
u/Internal_Pride1853 Mar 02 '24
Oh, I don’t remember now as it was quite a long time ago. But I think they were run inside the container but copied from Windows. I just Googled „docker sh not found” and the first stackoverflow result has a similar issue described and explanation why that does that happen.
I think I'll remember this for so long because it was my first issue to solve in a project and no one knew what's happening because the whole other team worked on Macs and I was a fresh hire 😂😂
And each new hire with Windows had the same issue which I was helping to resolve until we updated the dockerfile
-5
u/alex-weej Feb 23 '24
"With Docker?" Yes - people do apt-get install in their Dockerfiles a lot.
6
u/oze4 Feb 23 '24
Care to elaborate? I'm not sure I follow - are you saying because some people have Windows, apt wont work? (or any other OS that doesn't have apt).
Won't the apt-get command be running inside of the container?
Again, I'm being genuine here, not trying to argue or what not.
1
Feb 24 '24
apt-get will install the latest binary in the repository, like what npm install does , therefore you cannot guarantee a reproducible build.
1
u/oze4 Feb 24 '24
But you can pin dependencies to specific versions, at least with NPM. Can you not do that with apt-get?
2
u/dcabines Feb 23 '24
I’d compare Nix to Ansible long before I’d compare it to Docker.
1
u/alex-weej Feb 23 '24
As far as I know, solutions like Ansible are inherently non-reproducible and are more about scaffolding infrastructure than applications. Maybe something changed in the last few years though?
This is a good, recent video that might convince you of my point (if you like that sort of thing): https://youtu.be/0ulldVwZiKA
41
u/ben_db Feb 23 '24
I use pm2 in docker, am I going to hell?
8
u/fabiotrezzi Feb 23 '24
Me too. I use docker to create and environment identical in development and production and I use pm2 to handle multiple instances. Pm2 is also very useful because it can check the memory usage and restart the process after a threshold to prevent memory leaks to kill the server
6
2
2
1
1
1
1
29
Feb 23 '24
[removed] — view removed comment
14
u/bytepursuits Feb 23 '24 edited Feb 23 '24
Just, why
because you don't typically have single core CPU. If you want better performance you would want multiprocessing and you need to create as many node.js processes as there are vCPUs (well math depends on the application really) - but this is the idea.
yes it depends on where you host your application. With ecs or kubernetes you probably want to scale using ECS/kubernetes features, but if you are on large EC2 - then pm2 is still useful
2
Feb 23 '24
[removed] — view removed comment
4
u/iwrestlecode Feb 23 '24
You would not use docker but containers/images which previously typically were built by docker.
5
u/bytepursuits Feb 23 '24 edited Feb 23 '24
Ok but in that last case, why would I use docker and not only pm2 alone?
You may need to work on multiple versions of node.js (we juggle 14-21) or multiple versions of other languages like PHP or python on Go.
Typically these days you ALWAYS containerize for production, this may or may not need PM2, but containers are pretty much the golden standard.4
u/ben_db Feb 23 '24
The host I run on for some reason allocates two processors to docker, so I run it with
-i maxand it runs two instances
17
u/yossarianyells Feb 23 '24
I am using pm2 inside Docker container to use all the cores on the machine for my NextJS app. But now I realised I can use Nginx and multiple docker container (one per core) and say bye to pm2 :(
Why did I not read this thread before spending hours working around pm2-runtime messing up path for the source code
3
u/Tiis__ Feb 23 '24
Isn't Docker containers using all available cores if not specified?
6
u/yossarianyells Feb 23 '24
Yeah but running processes parallelly will have to be configured. In case of Nodejs based applications it can either be done via using a single container and use pm2-runtime within to manage parallel processes. Or run multiple docker containers by passing 'scale' flag to run your docker service and use Nginx as a load balancer
1
u/Hehehelelele159 Feb 24 '24
What would be the benefit of pm2 in one container vs nginx and multiple
1
u/Redicus Feb 25 '24
So currently your NextJS webapp uses all cores with PM2?
Now if you use Nginx with 1 container per core, wont your NextJS webapp/container only run on one core?
1
u/ZachVorhies Feb 26 '24
Right because it make more sense to spin up an virtual machine than launch a process.
😆
7
u/stevefuzz Feb 23 '24
I run pm2 in docker. Is this like a threesome?
2
9
5
u/backdoorsmasher Feb 23 '24
The last thread seemed to be very lite on people talking about clustering - that is one of the major advantages of PM2. Keen to hear how people are clustering with just docker
2
u/wilsonodk Feb 27 '24
My container orchestration software handles the "clustering". My personal preference is to use Kubernetes, but YMMV. Would much rather run multiple instance of the container as it gives better
insight into how an individual container runs (it's much easier to reason about a single container being a single entity versus having to divide by the number of instances inside the container),
it's easier to run across network zones (ie, AWS AZs),
gives better uptime/availability (when a container fails instead of losing multiple instances, only lose one)
letting software that dedicated to orchestration worry about orchestration versus having developers try to figure it out
much easier to "bin pack" the infrastructure (can autoscale the underlying VMs when needed and autoscale the container instances to get the most out of the VMs)
Those are just a few of the reasons. There are also error scenarios that a much easier to recover from that I list in another post.
1
4
u/Nice_Aioli_9991 Feb 23 '24 edited Feb 23 '24
Why? Does the docker can automatically start application when it crash?
21
u/Chaphasilor Feb 23 '24
Sure. Pass
--restart-unless-stopped, I believe3
u/Senior-Minute-9364 Feb 25 '24
If I’m not mistaken it restarts with exit code 0 too - I would use --restart on-failure to ensure it only restarts with exit code 1 and successfully stops with 0
4
Feb 24 '24
I use pm2 when I need to persist a simple node process. I use docker when I want to containerize an application. Are you mouth breathers reaching for docker when you need simple persistence? Tf?
2
2
u/polish_jerry Feb 23 '24
If I have to run just a node js script with no scaling then I'm not going to use docker.
1
u/dawar_r Feb 23 '24
I felt this for PM2 -> Docker and then again from Docker -> Kubernetes XD
1
u/Hour-Ladder-8330 Feb 25 '24 edited Feb 25 '24
Wait till there is kubernetes-> something coming soon to manage working with kubernetes easy
1
u/dawar_r Feb 25 '24
A Kubernetes AI? Imagine managed kubernetes but the best possible admin for free
1
u/Shehzman Feb 27 '24
Started off using PM2 for a simple node app I built. Switched it over to a docker container and I’m so glad I did. It is significantly easier to deploy and manage.
1
1
1
u/mnaa1 Feb 23 '24
Never liked pm2, added overhead complexity to a simple node application. I just went for a 1vCPU and 2GB memory per instance and never looked back.
-1
u/Illustrious_Pie_8197 Feb 23 '24
I don't know why pm2 is forced upon developers in private insurance sector and black list docker.
-2
4
u/[deleted] Feb 23 '24
I use Docker and PM2, am I doing it wrong?