From 08bc8dfe2a6a86e44961291c5f3f310369375fc9 Mon Sep 17 00:00:00 2001 From: Emin Arslan Date: Wed, 30 Oct 2024 18:46:43 +0300 Subject: [PATCH] Clean up the setup page a little --- content/posts/setup_p1.md | 98 ++++++++++++++-------------- public/index.xml | 2 +- public/posts/index.html | 4 +- public/posts/index.xml | 2 +- public/posts/setup_p1/index.html | 108 ++++++++++++++----------------- 5 files changed, 100 insertions(+), 114 deletions(-) diff --git a/content/posts/setup_p1.md b/content/posts/setup_p1.md index bd21267..367e705 100644 --- a/content/posts/setup_p1.md +++ b/content/posts/setup_p1.md @@ -1,5 +1,7 @@ +++ title = 'My Setup - p1' +subtitle = 'Containers!' +summary = "I go over the things I've learned about docker, and how I've used it to host my website." date = 2024-10-25T23:11:17+03:00 draft = false +++ @@ -25,71 +27,69 @@ This is a cumbersome process. The whole point of using hugo is to *focus on the writing*, so having to zip and reupload for every typo is... not great. I wanted to be able to do a simple `git push`, and not worry about the rest. -The previous "manual" approach also depends on me having already installed all +The "manual" approach also depends on me having already installed all necessary software. If you have a dedicated server that you're running yourself, that's probably okay, you just have to setup once, but I'm running this on a VPS that I'm not sure I'll keep forever. The ability to reproduce this exact setup within minutes actually matters. -After reading a bit on this topic, I decided I would use podman for this. Docker +After reading a bit on this topic, I decided I would use docker for this. Podman would work just as nicely (any containerization software would work, really), -but I decided on podman because it can run without a daemon and without root -privilages. Also, it has pretty neat support for kubernetes pods (which are -honestly a lot more useful than I would've given them credit for before I started -this whole project). - -That's really why I'm writing this. So that you, the reader (or possibly my future self) can -understand the methodology of podman, how to create pods, run containers and configure all -of this automatically, and so that I may demonstrate and share what I've learnt during -this process. +but I decided on docker because it's been the standard for a while now ## Motivation -Basically, I'm already running a web server. Why shouldn't I also host several other services -for friends and family while I'm at it? Why shouldn't I make the entire setup reproducable? +Basically, I'm already running a web server. Why shouldn't I also host several +other services for friends and family while I'm at it? Why shouldn't I make the +entire setup reproducible? Here are some of the services I wanted to self-host: - - Web server: obviously, who doesn't want a website? - - Some git server: having my own place to show off all the things I've done is certainly really cool. - - Wireguard: Free VPN along with the website? sign me up. - - CI/CD: automatic testing and releases of my software is cool, and also incredibly useful because that's -how I plan to handle the website as well. -Of course, there are always more things I could be self-hosting. So it makes sense to automate -the setup, and that's where podman comes in. +- Web server: obviously, who doesn't want a website? +- Some git server: having my own place to show off all the things I've done is +certainly really cool. For this, something like [Gitea](https://about.gitea.com/) +would normally be great. I went with [Gogs](https://gogs.io/) instead, because +it is far more lightweight. +- Wireguard: Free VPN along with the website? sign me up. +- CI/CD: automatic testing and releases of my software is cool, and also +incredibly useful. -## Basics of podman +Of course, there are always more things I could be self-hosting. So it makes +sense to automate the setup, and that's where docker comes in. -Before we can get to the exciting stuff, we need to go over what podman is, and how to -use it. Essentially, podman is a container engine: it lets you build and run applications in -a containerized environment. Containers are useful because they provide security, -easy setup and most importantly, reproducability. +## Basics of docker + +Before we can get to the exciting stuff, we need to go over what docker is, and how to +use it. Essentially, docker is a container engine: it lets you build and run +applications in a containerized environment. Containers are useful because they +provide security, easy setup and most importantly, reproducibility. I'm not going to spend any more time explaining what containers are and why they're good, that's been done to death already. Right now, what matters is the actual setup, so let's get on with it. If you've used docker before, you'll feel right at home. Many commands are unchanged -from docker, making podman a suitable drop-in replacement. Some things like network +from docker, making docker a suitable drop-in replacement. Some things like network setups tend to be a little different, but that won't matter too much right now. -In case you're unfamiliar with docker, here are some basic commands: +In case you're unfamiliar with docker, here are some basic commands (run these +either as root, or as a user in the `docker` group): ```sh # Search for container images (on docker.io unless you configure otherwise) -$ podman search +$ docker search # Download (pull) an image from remote repo -$ podman pull +$ docker pull # list the images you have pulled. -$ podman images +$ docker images # run a container. -$ podman run +$ docker run # run a container, but with a LOT of flags. I just listed the most useful ones. -$ podman run +$ docker run -i # interactive, so you can e.g. run a shell in the container -t # allocates a tty. useful with -i so that shell completion etc. can work -d # opposite of -i, detach and run in the background @@ -99,35 +99,31 @@ $ podman run # ... want a shell? # list running containers. add -a to list ALL containers, running or stopped. -# podman ps <-a> +$ docker ps <-a> # stop a running container. -$ podman stop +$ docker stop # stopped containers don't automatically get removed. This command removes it. -$ podman rm +$ docker rm ``` -## Pods are nice. +## Compose is nice. -Pods are basically just a collection of containers - multiple programs working -with each other. +Docker compose is a nice way to essentially "group together" some containers, +and ship them in an easy way. Usually, on a server, each application *isn't* totally separate from each other -- for my own usecase, I want my git server (e.g. gogs) to automatically build +- for my own use case, I want my git server (e.g. gogs) to automatically build and update my website whenever I push to its git repository. That means my git server and web server can't be *totally* separate, there's some amount of -relation. Pods can help with this. +relation. -Pods allow you to create a "pod" containing several containers, sharing resources -with each other, etc. For example, I could run a pod with nginx and gogs running -in seperate containers - then, the nginx server could act as a reverse proxy -based on host name, showing the web page on emin.software, and the git server on -git.emin.software. Nginx redirects to gogs which only binds to *the pod's -localhost address*, so only nginx can reach it. Likewise, a database server can -be added to the pod only for the git server to use, so that it can't be reached -from the outside the pod - and it is logically grouped along with the rest of -the pod. +At the same time... I don't really want to set up both containers, then their +volumes, and their ports etc. by hand. Sure I could stick it in a shell script, +but that's hardly elegant. -On top of this, pods can be built purely from a kubernetes-compatible -configuration file, so setting them up is relatively easy. +Docker compose helps with this: you can create a +`compose.yaml` file, and define containers, ports, volumes, secrets all inside +this file. Then, when you run `docker compose up` this configuration is read, +and all of it is processed as you would want it to. diff --git a/public/index.xml b/public/index.xml index 394b00e..785b270 100644 --- a/public/index.xml +++ b/public/index.xml @@ -13,7 +13,7 @@ https://emin.software/posts/setup_p1/ Fri, 25 Oct 2024 23:11:17 +0300 https://emin.software/posts/setup_p1/ - My Setup In this &lsquo;series&rsquo; I will be walking you through my process of how I host everything on this server. I&rsquo;m currently running, on top of my blog, a gogs instance. When first creating this website, I just had my blog. I generated this blog using hugo: a static site generator. Hugo allowed me to focus on writing whatever I wanted in Markdown format, it would take care of converting my writing into HTML and CSS. + I go over the things I&rsquo;ve learned about docker, and how I&rsquo;ve used it to host my website. About diff --git a/public/posts/index.html b/public/posts/index.html index 003659c..5b38523 100644 --- a/public/posts/index.html +++ b/public/posts/index.html @@ -158,9 +158,7 @@ My Setup - p1

- My Setup In this ‘series’ I will be walking you through my process of how I host everything on this server. -I’m currently running, on top of my blog, a gogs instance. -When first creating this website, I just had my blog. I generated this blog using hugo: a static site generator. Hugo allowed me to focus on writing whatever I wanted in Markdown format, it would take care of converting my writing into HTML and CSS. + I go over the things I’ve learned about docker, and how I’ve used it to host my website.

diff --git a/public/posts/index.xml b/public/posts/index.xml index 4a1a6f9..b3249b8 100644 --- a/public/posts/index.xml +++ b/public/posts/index.xml @@ -13,7 +13,7 @@ https://emin.software/posts/setup_p1/ Fri, 25 Oct 2024 23:11:17 +0300 https://emin.software/posts/setup_p1/ - My Setup In this &lsquo;series&rsquo; I will be walking you through my process of how I host everything on this server. I&rsquo;m currently running, on top of my blog, a gogs instance. When first creating this website, I just had my blog. I generated this blog using hugo: a static site generator. Hugo allowed me to focus on writing whatever I wanted in Markdown format, it would take care of converting my writing into HTML and CSS. + I go over the things I&rsquo;ve learned about docker, and how I&rsquo;ve used it to host my website. diff --git a/public/posts/setup_p1/index.html b/public/posts/setup_p1/index.html index 5ce80b8..7971cbc 100644 --- a/public/posts/setup_p1/index.html +++ b/public/posts/setup_p1/index.html @@ -46,9 +46,7 @@ - + @@ -58,9 +56,7 @@ When first creating this website, I just had my blog. I generated this blog usin - +