opened image

How to install AdGuard Home in Docker

Advertising and trackers can follow you. In most cases, advertising may be inappropriate. Thanks to trackers, your personal information will be used to determine the most effective way to sell you any product. Both banner ads and trackers slow down the browser, interfere with, and degrade the online experience. 

AdGuard Home is software that provides security for your network and blocks ads and trackers. In this article, we will look at how to install it in a Docker container, also using docker-compose.
 

Let's install Docker. 

Update the OS packages. 
 

apt update


We will install the necessary packages and add a new repository:

 

 

 

apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

 


We will update the packages with the new repository:

 

 

 

 

apt update

 


Now let's install Docker.

 

 

 

 

apt-get install docker-ce docker-ce-cli containerd.io

 


Let's check the version:

 

 

 

 

docker --version

 




Let's check the status:

 

 

 

 

systemctl status docker

 




If it hasn't started, we start it:

 

 

 

 

systemctl start docker

 


And add it to autostart.

 

 

 

 

systemctl enable docker

 

 

 

 

 

Let's install Docker-Compose


For this project, version 1.25 will be sufficient. 

 

 

 

 

 

 

curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

 


We set the execution permissions. 

 

 

 

 

chmod +x /usr/local/bin/docker-compose

 


Let's check how Docker-Compose was installed:

 

 

 

 

docker-compose --version

 





Add the Linux user to the docker group:

 

 

 

 

usermod -aG docker $USER

 


Let's create a *.yaml  file for Docker-Compose.

To keep track of what we have installed in the future, let's create a separate folder for this project in the /home directory and navigate to it.

 

 

 

 

mkdir /home/adguardhome && cd /home/adguardhome

 


You can also use another directory  to place this and other projects. 

Let's use the repository to create the docker-compose.yaml file at the link https://hub.docker.com/r/adguard/adguardhome

Create the file docker-compose.yaml or docker-compose.yml,

 

 

 

 

vim docker-compose.yaml

 


And add the following code to it:

 

 

 

 

version: '3.3'
services:
    adguardhome:
        image: adguard/adguardhome
        container_name: adguardhome
        volumes:
            - /opt/adguardhome/work:/opt/adguardhome/work
            - /opt/adguardhome/conf:/opt/adguardhome/conf
        ports:
            - 53:53/tcp
            - 53:53/udp
            - 67:67/udp
            - 68:68/udp
            - 80:80/tcp
            - 443:443/tcp
            - 443:443/udp
            - 3000:3000/tcp
            - 853:853/tcp
            - 784:784/udp
            - 853:853/udp
            - 8853:8853/udp
            - 5443:5443/tcp
            - 5443:5443/udp
        restart: always

 

Where:

container_name: the name of your container;
In the volumes  block, specify the paths where the configuration files will be available;
In the ports  block, the ports that need to be forwarded to the container are specified.


Run the script (to do this, you need to be in the directory where our file was created. In this case, it is /home/adguardhome/):

 

 

 

 

docker-compose up -d 

 


Wait for the images to download and deploy.

Check:

 

 

 

 

docker-compose ps

 


Or:

 

 

 

 

docker ps

 



You can also install adguardhome with a single command without using docker compose.

 

 

 

 

docker run --name adguardhome\\
    --restart unless-stopped\\
    -v /my/own/workdir:/opt/adguardhome/work\\
    -v /my/own/confdir:/opt/adguardhome/conf\\
    -p 53:53/tcp -p 53:53/udp\\
    -p 67:67/udp -p 68:68/udp\\
    -p 80:80/tcp -p 443:443/tcp -p 443:443/udp -p 3000:3000/tcp\\
    -p 853:853/tcp\\
    -p 784:784/udp -p 853:853/udp -p 8853:8853/udp\\
    -p 5443:5443/tcp -p 5443:5443/udp\\
    -d adguard/adguardhome

 


Now, to access the administration panel, you need to disable DNSStubListener on the server. To do this, create a directory and a new file:

 

 

 

 

mkdir -p  /etc/systemd/resolved.conf.d
vim /etc/systemd/resolved.conf.d/adguardhome.conf

 
And add the following code to it:
 

[Resolve]
DNS=127.0.0.1
DNSStubListener=no


To activate resolve.conf, execute the following commands:

 

 

 

mv /etc/resolv.conf /etc/resolv.conf.backup
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

 


Update DNSStubListener:

 

 

 

 

systemctl reload-or-restart systemd-resolved

 


Now we can use our IP to connect to adguardhome and complete the installation. After that, you can log in with the credentials you entered during installation. 


You will see a picture similar to this in your personal account. 


To make adguardhome start blocking ads, enter the server IP where adguardhome is located in the DNS field. This can be done both in the router and on your personal PC.


Happy surfing without trackers and ads.