End Users Out In The World
In this article, we will guide you through setting up a self-hosted infrastructure for your applications, focusing on creating an efficient and automated homelab environment using popular open-source tools. This.
# End Users Out In The World
In this article, we will guide you through setting up a self-hosted infrastructure for your applications, focusing on creating an efficient and automated homelab environment using popular open-source tools. This will empower you as a DevOps engineer to manage your own applications, giving you greater control over your digital ecosystem.
Prerequisites
To follow this tutorial, ensure you have the following prerequisites installed:
Ubuntu 20.04 LTS or later: This article is based on Ubuntu 20.04 LTS. If you are using a different Linux distribution, adjust the commands accordingly.
- Docker CE v5.0.8+: Install Docker with the following command:
1
apt-get update && apt-get install docker-ce=5.0.8 -y
- Docker Compose v1.27.4+: Install Docker Compose with the following command:
1 2
curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
Setting Up Your Homelab
- Create a new directory for your project:
1
mkdir my-homelab && cd my-homelab
- Create a Docker Compose configuration file:
1
touch docker-compose.yml
Configure the Docker Compose file:
In this example, we will create a simple web application using Nginx as a reverse proxy and PostgreSQL as the database. Here is the
docker-compose.yml
configuration:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
version: "3" services: app: build: . ports: - "80:80" depends_on: - db db: image: postgres:latest environment: POSTGRES_USER: myuser POSTGRES_PASSWORD: mypassword POSTGRES_DB: mydb
This configuration will build your application in the current directory (
.
), map port 80 on your host machine to port 80 inside the container, and create a PostgreSQL service with the specified environment variables.Build your application:
To make your application ready for deployment, create a
Dockerfile
in the root directory of your project:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
FROM node:latest as build # Install dependencies WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build # Create runtime environment FROM node:latest WORKDIR /app COPY --from=build /app . EXPOSE 80 CMD [ "npm", "start" ]
Replace
node
with the appropriate base image for your application.Deploy your homelab:
Start your services using Docker Compose:
1
docker-compose up -d
Troubleshooting
- Ensure that you have the required prerequisites installed and versions are compatible with the commands used in this tutorial.
- Verify that your
Dockerfile
is correct, and the specified base image is available on Docker Hub or another container registry.
Conclusion
By setting up a self-hosted homelab, you can gain valuable experience managing your own applications while leveraging popular open-source tools. This will further expand your DevOps skillset and allow for greater control over your digital ecosystem. Keep exploring and automating!