Jump to content
×
×
  • Create New...

[Linux] Converting your RSPS server to use Docker (In Progress)


Recommended Posts

Hey there. I'm here to show you how to make your server run on Docker using a Linux host. Now, there are a lot of variables here that need to be considered but we're going to run with the 2 most basic types of setups here:

  1. Server running solely with docker-compose (can somewhat be integrated with Git CI's, preferably use images though).
  2. Server running with built images (can be integrated with Git CI's).

The first set we will go through is using docker-compose. But first, we need to setup Docker, right? So let's go and do that. But, do checkout my Gist for useful things for any experienced administrators out there: https://gist.github.com/Atomic-Molecule everything here is created by me and all custom.

Setting up Docker Engine

First things first, Docker has commendable documentation, so I suggest you use this as your main resource at most times anytime you have questions regarding on how to do something. Stack is also a prominent ground of information for this, as any other. 

I will presume you already have your Linux distribution installed on your machine, I recommend going with CentOS 7/8, Debian Stretch or Buster (9 or 10), not Ubuntu, mainly because there is so much bloat on that distribution now it might as well be under the same roof as Windows. They do have minimal installs, but Ubuntu is tuned more for friendliness over Debian which allows more freedom. But, we won't get into that, it would require a whole other discussion post for it.  

Initially, make sure you don't have any Desktop Environments installed, if you do , reinstall your system headless no GUI otherwise you're going to get pointless overhead and you'll need as much as possible from your resource pool to make this setup effective. GUI is for noobs anyway ;).

In the following steps I will show instructions for both CentOS and Debian, mostly the same but some differences. Any other distribution like Arch or anything you will need to just mitigate the commands, i.e. if I tell you to run updates and you do have Arch, it will be pacman -Syu instead of yum update && yum upgrade.

We will be following Docker documentation throughout this tutorial: https://docs.docker.com/engine/install/centos/ | https://docs.docker.com/engine/install/debian/

I'm going to simplify the installation steps without the text information inbetween. Otherwise, skip this tutorial and follow straight from their site and come back here when done.

Once your machine is installed, first thing you make sure you do is ensure you have internet:

Debian/CentOS:

[email protected]:# ping 8.8.8.8

After you ping Google's DNS and you get a reply, continue with updating your machine.:

[email protected]:# yum update && yum upgrade

[email protected]bian-machine:# apt update && apt upgrade

It's a must for you to be updated because there are build-essential tools the Docker source repo's rely on, you'll have a hell of a time otherwise.

Now, run the following commands in order to install the Docker Engine::

Debian

[email protected]:# apt install apt-transport-https ca-certificates curl gnupg lsb-release # Allow HTTPS for key verification

[email protected]:# curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg # Add docker gpg key for verifying downloads

[email protected]:# echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null # Setup the repository to download docker engine
  
[email protected]:# apt update && apt install docker-ce docker-ce-cli containerd.io

CentOS

[email protected]:# yum install -y yum-utils

[email protected]:# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

[email protected]:# yum install docker-ce docker-ce-cli containerd.io

All done! But wait, we need to perform post-installation steps because you should not be running Docker containers as root unless you're in a test environment and need to use it this way for ease. However, the Docker grou The next thing we need to do is create a user, add that user to the Docker group, make sure they can use Docker, and lastly ensure Docker will run on boot otherwise you need to do this manually.

Debian/Centos

[email protected]:# groupadd docker # THIS MAY REPORT THAT THE GROUP ALREADY EXISTS! IF SO, CONTINUE!

[email protected]:# useradd Username && usermod -aG docker Username

[email protected]:# systemctl enable docker && systemctl enable containerd # Makes docker boot on start

Now, we're ready to test that Docker is actually working. Run the following command to ensure it does:

Debian/CentOS

[email protected]:# docker run hello-world

You should see output looking similar to this:

[[email protected]~]$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Vuala! You can now start using Docker.

Setting up Docker-Compose

I'm not going to bother putting instructions here for this nor describe what it is, it's two commands from their documentation: https://docs.docker.com/compose/install/ - start getting used to reading it from the getgo.

Using Docker

Now for the juicy part. Let's get down and dirty with docker. First we'll go over using docker-compose and how it works, here is an example configuration:

version: '3.2'
services:

  website:
    image: 'nginx:1.15.1-alpine'
    ports:
      - '123.23.43.54:80:80'
      - '123.23.43.54:443:443'
    volumes:
      - type: bind
        source: /path/to/website/folder
        target: /var/www/default/
      - './nginx_config/nginx.conf:/etc/nginx/nginx.conf'
      - './nginx_config/website.conf:/etc/nginx/conf.d/website.conf'
      - './nginx_config/mime.types:/etc/nginx/mime.types'
      - './SSL/:/etc/nginx/ssl/'
    networks:
      production:
        ipv4_address: 172.50.1.5

  website_php:
    build:
      context: .
      dockerfile: dockerfiles/php-dockerfile
    volumes:
      - type: bind
        source: /path/to/website
        target: /var/www/default/
      - './php_config/php.ini:/usr/local/etc/php/php.ini'
    networks:
      production:
        ipv4_address: 172.50.1.3

  website_sql:
    image: 'mysql:8.0.17'
    ports:
      - '123.123.123.123:3306:3306'
    environment:
      - MYSQL_ROOT_PASSWORD=enjoythegist
    volumes:
      - 'sql-volume-name:/var/lib/mysql'
    command:
      - '--skip-mysqlx'
    networks:
      production:
        ipv4_address: 172.50.1.4

networks:
  production:
    ipam:
      driver: default
      config:
        - subnet: 172.50.0.0/16

volumes:
  sql-volume-name: null

There is a lot to unpack in this configuration, so let me go over it bit by bit:

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now