Pos

Nginx Proxy Manager Networking

Fungsi

Nginx Proxy Manager berperanan sebagai reverse proxy kepada webapp dalam server.

image-2.png

Objektif

Dapat configure static networking docker mengunakan Nginx Proxy Manager (NPM) seperti gambar di bawah.

Gambarajah Tanpa Tajuk.drawio.png

Environment

  • Ubuntu 22.04 LTS
  • Docker 20.10.12

Install docker

1
2
sudo apt install docker.io
sudo apt install docker-compose

Bina docker-compose file NPM

1
2
3
4
mkdir npm
cd npm
touch docker-compose.yaml
nano docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - data:/data
      - letsencrypt:/etc/letsencrypt
    networks:
      npm-network:
        ipv4_address: 172.19.0.2
        
volumes:
  data:
  letsencrypt:
  
networks:
  npm-network:
    ipam:
      driver: default
      config:
        - subnet: "172.19.0.0/24"

Run docker-compose

1
sudo docker-compose up -d

List docker network

1
2
3
4
5
6
sudo docker network ls
NETWORK ID     NAME                         DRIVER    SCOPE
d63470120ca8   bridge                       bridge    local
2221f68bf40d   host                         host      local
b3bd7a7d7c41   none                         null      local
a39cfebb3cfe   npm_npm-network              bridge    local

Bina docker-compose file Wordpress

1
2
3
4
mkdir wordpress
cd wordpress
touch docker-compose.yaml
nano docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
version: "3.9"
    
services:

  wordpress-db:
    image: mariadb
    volumes:
      - wordpress-db:/var/lib/mysql
    restart: unless-stopped
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
      - MYSQL_PASSWORD=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_DATABASE=wordpress
    networks:
      wordpress-back-network:
    
  wordpress:
    depends_on:
      - wordpress-db
    image: wordpress:latest
    volumes:
      - wordpress_data:/var/www/html
    ports:
      - 80 # only exposing internal port to npm-network
    restart: unless-stopped
    environment:
      WORDPRESS_DB_HOST: wordpress-db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    networks:
      wordpress-back-network:
      npm_npm-network:
        ipv4_address: 172.19.0.2


volumes:
  wordpress-db: 
  wordpress_data: 

networks:
  wordpress-back-network:
    driver: bridge
  npm_npm-network: #connecting to the exisisting network
    external: true

List dan inspect docker network

1
2
3
4
5
6
7
sudo docker network ls
NETWORK ID     NAME                         DRIVER    SCOPE
d63470120ca8   bridge                       bridge    local
2221f68bf40d   host                         host      local
b3bd7a7d7c41   none                         null      local
a39cfebb3cfe   npm_npm-network              bridge    local
b3bd7a7d7c65   wordpress-back-network       bridge    local
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
sudo docker network inspect npm_npm-network
[
    {
        "Name": "npm_npm-network",
        "Id": "a39cfebb3cfe6d82a77c69251ca4e78e02abed0a752240796bc6c96a7a0090bd",
        "Created": "2022-06-05T12:05:38.861192412Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.16.238.0/24",
                    "Gateway": "172.16.238.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ba23f260105e68296b4c346640774963176bc3d93dd42a1234023ea2b40bfdca": {
                "Name": "npm_app_1",
                "EndpointID": "8638f90956697c900fc904e47d178531c97706290019f833196b8b2d4330ee8f",
                "MacAddress": "02:42:ac:10:ee:10",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "f958e696d6b952b97806df0e7bebe3ea2cb3f077e8e45fb36d2c0847bf81954d": {
                "Name": "wordpress_app_1",
                "EndpointID": "b3c5a33bd1118e0a7dc03e648609eb4bcc2372dda1a1a16c2e1182267fa0864b",
                "MacAddress": "02:42:ac:10:ee:0a",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "npm-network",
            "com.docker.compose.project": "npm",
            "com.docker.compose.version": "1.25.0"
        }
    }
]

Note npm container run pada IP 172.18.0.2 dan wordpress container run pada IP 172.18.0.3

Bina docker-compose file nginx

1
2
3
4
mkdir nginx
cd nginx
touch docker-compose.yaml
nano docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: '3'

services:
  nginx:
    image: nginx:latest
    restart: unless-stopped
    ports:
      - 80 # only exposing port to the npm-network
    volumes:
      - ./src:/usr/share/nginx/html
    networks:
        npm_npm-network:
          ipv4_address: 172.19.0.4
          
networks:
  npm_npm-network: #connecting to the exisisting network
    external: true

Inspect kembali docker network

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
sudo docker network inspect npm_npm-network
[
    {
        "Name": "npm_npm-network",
        "Id": "a39cfebb3cfe6d82a77c69251ca4e78e02abed0a752240796bc6c96a7a0090bd",
        "Created": "2022-06-05T12:05:38.861192412Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.16.238.0/24",
                    "Gateway": "172.16.238.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ba23f260105e68296b4c346640774963176bc3d93dd42a1234023ea2b40bfdca": {
                "Name": "npm_app_1",
                "EndpointID": "8638f90956697c900fc904e47d178531c97706290019f833196b8b2d4330ee8f",
                "MacAddress": "02:42:ac:10:ee:10",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "f958e696d6b952b97806df0e7bebe3ea2cb3f077e8e45fb36d2c0847bf81954d": {
                "Name": "wordpress_app_1",
                "EndpointID": "b3c5a33bd1118e0a7dc03e648609eb4bcc2372dda1a1a16c2e1182267fa0864b",
                "MacAddress": "02:42:ac:10:ee:0a",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
            "jbqwuebwqubeuwqew7678e6wqhegwquge12tfvhvhj12ijij21j7656hgvvacttat": {
                "Name": "nginx_app_1",
                "EndpointID": "b3c5a33bd1118e0a7dc03e648609eb4bcc2372dda1a1a16c2e1182267fa0864b",
                "MacAddress": "02:42:ac:10:ee:0a",
                "IPv4Address": "172.18.0.4/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "npm-network",
            "com.docker.compose.project": "npm",
            "com.docker.compose.version": "1.25.0"
        }
    }
]

Note npm container run pada IP 172.18.0.2, wordpress container run pada IP 172.18.0.3 dan nginx container run pada IP 172.18.0.4

Langkah akhir

Login ke NPM admin page (http://localhost:81/) dan mula configure domain menuju kepada docker container.

Tangkap layar 2022-06-09 081716.png

Pos ini dilesenkan di bawah CC BY 4.0 oleh penulis.