Here’s how you can proceed step by step to deploy gyanarth.in and gyanarth.com on docker server:
Step 1. Set Up Docker and Docker Compose
Ensure Docker and Docker Compose are installed on your server. If not, install them:
sudo apt update
sudo apt install docker.io docker-compose -y
Step 2. Create a Directory for Your Projects
Organize your websites in separate folders under a common directory. For example:
/var/www/
├── gyanarth.in/
├── gyanarth.com/
└── reverse-proxy/
Step 3. Set Up Each Website with a Dockerfile
Each website can have its own Dockerfile
. For example, for gyanarth.in
:
Dockerfile:
FROM nginx:latest
COPY ./public /usr/share/nginx/html
Place your website files in a public
folder in gyanarth.in
.
Step 4: Configure Domains
- Point the A records for both
andgyanarth
.in
to your server’s public IP address.gyanarth
.com
Step 5: Create Directory Structure
Run the following commands on your server:
mkdir -p /var/www/gyanarth.in /var/www/gyanarth.com
Step 6: Set Up docker-compose.yml
for Each Website
For gyanarth.in
1. Navigate to the directory:
cd /var/www/gyanarth.in
2. Create a docker-compose.yml
file
version: '3.8'
services:
babhan_pro:
image: nginx:latest
container_name: gyanarth_in
volumes:
- ./public:/usr/share/nginx/html:ro
networks:
- proxy
environment:
- VIRTUAL_HOST=gyanarth.in
- LETSENCRYPT_HOST=gyanarth.in
- LETSENCRYPT_EMAIL=youremail@example.com
restart: unless-stopped
networks:
proxy:
external: true
3. Add your website content:
mkdir public
echo "<h1>Welcome to gyanarth.in</h1>" > public/index.html
For gyanarth.com
1. Navigate to the directory:
cd /var/www/gyanarth.com
2. Create a docker-compose.yml
file:
version: '3.8'
services:
babhan_com:
image: nginx:latest
container_name: gyanarth_com
volumes:
- ./public:/usr/share/nginx/html:ro
networks:
- proxy
environment:
- VIRTUAL_HOST=gyanarth.com
- LETSENCRYPT_HOST=gyanarth.com
- LETSENCRYPT_EMAIL=youremail@example.com
restart: unless-stopped
networks:
proxy:
external: true
3. Add your website content:
mkdir public
echo "<h1>Welcome to gyanarth.com</h1>" > public/index.html
Step 6: Set Up the Reverse Proxy
The reverse proxy will handle requests for both domains and route them to the correct containers.
1. Navigate to the reverse-proxy
directory:
mkdir -p /var/www/reverse-proxy
cd /var/www/reverse-proxy
2. Create the docker-compose.yml
for Nginx Proxy Manager:
version: '3.8'
services:
nginx-proxy:
image: 'jc21/nginx-proxy-manager:latest'
container_name: nginx-proxy
ports:
- '80:80'
- '443:443'
- '81:81'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
networks:
- proxy
restart: unless-stopped
networks:
proxy:
name: proxy
3. Start the reverse proxy:
docker compose up -d
3.1. Access the Nginx Proxy Manager UI
- Open your web browser and navigate to:
http://<your-server-ip>:81
Replace<your-server-ip>
with the public or private IP address of your server. For example:- If your server is hosted locally:
http://192.168.1.100:81
- If hosted on a cloud VPS:
http://123.45.67.89:81
- If your server is hosted locally:
3.2. Default Credentials
The default login credentials for Nginx Proxy Manager are:
- Username:
admin@example.com
- Password:
changeme
3.3. Change the Default Login
- After logging in for the first time, you’ll be prompted to update your details:
- Set a new email address.
- Create a secure password.
- Save the changes, and you’ll be redirected to the dashboard.
3.4. Configure Proxy Hosts
Once logged in, you can start configuring proxy hosts for your domains (gyanarth.in
and gyanarth.com
):
- Go to “Proxy Hosts” in the menu.
- Click “Add Proxy Host”.
- Fill in the details:
- Domain Names: Enter
orgyanarth
.in
(you’ll repeat this step for each domain).gyanarth
.com - Scheme:
http
. - Forward Hostname / IP: Enter the container name (
in orgyanarth
_
).gyanarth
_com - Forward Port: Use
80
(default for Nginx). - Enable SSL: Check the box for “Request a Let’s Encrypt SSL Certificate” and agree to the terms.
- Domain Names: Enter
- Save the configuration.
Step 7: Start Your Websites
1. Start the services for each website:
cd /var/www/gyanarth.in
docker compose up -d
cd /var/www/gyanarth.com
docker compose up -d
2. Verify all containers are running: docker ps
Step 8: Test Your Setup
- Open
http://gyanarth.in
andhttp://gyanarth.com
in your browser to ensure the websites are live and working.
Optional: Update Content
- To update your website content, replace the files inside the
public
directories forgyanarth.in
andgyanarth.com
and restart the services:
docker compose restart