Deploy Docker, Docker-Compose, Portainer and NPM (Nginx Proxy Manager) - NETSEC

Latest

Learning, Sharing, Creating

Cybersecurity Memo

Saturday, July 30, 2022

Deploy Docker, Docker-Compose, Portainer and NPM (Nginx Proxy Manager)

In this tutorial, you will learn to install and configure Docker, Docker-compose, the Portainer container management solution on a Linux server and use it to create and manage Docker containers to run different apps. You will also learn to put these containers behind Nginx using the Nginx proxy manager.The Nginx proxy manager (NPM) is a reverse proxy management system running on Docker. NPM is based on an Nginx server and provides users with a clean, efficient, and beautiful web interface for easier management.


Install Docker & Docker-Compose


Ubuntu System:


apt install docker.io -y && apt install docker-compose


CentOS System:

Install Docker on CentOS 8:

curl -sSL https://get.docker.com/ | sh 
systemctl start docker 
systemctl enable docker
Install Docker Compose on CentOS 8:
Important: Check the latest version of docker-compose from https://docs.docker.com/compose/release-notes/ then modify following command with latest version number. (I got 1.29.2 for this installation)


curl -L "https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose


Notes: 




Enable IPv6 and Limit Log File Size

 

Change some Docker's default configuration:

Add customized self defined IPv6 address segment to enable container's IPv6 fucntion. And limit log file's size and numbers in case log file to fill all hard drive's space. 

cat > /etc/docker/daemon.json << EOF
{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "20m",
        "max-file": "3"
    },
    "ipv6": true,
    "fixed-cidr-v6": "fd00:dead:beef:c0::/80",
    "experimental":true,
    "ip6tables":true
}
EOF

Restart Docker service:

systemctl restart docker



Install Portainer

Commands to install Portainer:

[root@arm1 ~]# docker volume create portainer_data
portainer_data
[root@arm1 ~]# docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
Access Portainer:
  • Make sure your VPS's 9000 port has been opened in your security group. 
Verify Portainer from Internet by visiting http://<VPS's Public IP>:9000

Install NPM

Method 1 - Portainer

add a new container using following configuration:

Restart policy : unless stopped
Volume using host folder :/data and /letsencrypt since ./ format is not accepted by Portainer. 




Method 2 - Docker-Compose YML file

  1. Install Docker and Docker-Compose
  1. Create a docker-compose.yml file similar to this:
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
  1. Bring up your stack by running
docker-compose up -d
  1. Log in to the Admin UI

When your docker container is running, connect to it on port 81 for the admin interface. Sometimes this can take a little bit because of the entropy of keys. You might want to open Port 81 from your cloud firewall / access-list. 

http://<Public IP>:81

Default Admin User:

Email:    [email protected]
Password: changeme

Immediately after logging in with this default user you will be asked to modify your details and change your password

Log in and change password.



Access NPM


1 Open the URL https://<YourServerPublicIP>:81 in your browser, and you will get the following screen. Enter the following default credentials to sign in.

Email address: [email protected] Password: changeme

2 Next, you will be immediately asked to set a name and an email address. Click the Save button, and you will be asked to create a new password. Click the Save button again to get started.



3 Visit the Hosts >> Proxy Hosts and click the Add Proxy Host button.



4 Enter the domain name as portainer.example.com. Choose the scheme as https. Enter the name of the container as the Forward Hostname and 9443 as the Forward port. Check the options Block Common Exploits and Websockets Support options.




Configure NPM for Portainer







Configure NPM for NPM

No comments:

Post a Comment