Post

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:

  1. 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.

  2. Docker CE v5.0.8+: Install Docker with the following command:
    1
    
    apt-get update && apt-get install docker-ce=5.0.8 -y
    
  3. 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

  1. Create a new directory for your project:
    1
    
    mkdir my-homelab && cd my-homelab
    
  2. Create a Docker Compose configuration file:
    1
    
    touch docker-compose.yml
    
  3. 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.

  4. 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.

  5. 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!

This post is licensed under CC BY 4.0 by the author.