This command runs an Nginx container as a reverse proxy with mounted config files and SSL certificates, then inspects the Docker network to see connected containers and their IPs.
Run Nginx Proxy Container
docker run -d \
--name nginx-proxy \
--network <your_network_name> \
--restart unless-stopped \
-p 80:80 \
-p 443:443 \
-v /home/ubuntu/nginx/conf.d:/etc/nginx/conf.d:ro \
-v /home/ubuntu/nginx/proxy_params:/etc/nginx/proxy_params:ro \
-v /home/ubuntu/nginx-certs:/etc/nginx/certs:ro \
nginx:alpine
Inspect Network Containers
docker network inspect <your_network_name> \
--format '{{range .Containers}}{{.Name}} → {{.IPv4Address}}{{"\n"}}{{end}}'
Connect / Disconnect Container to Network
Manually attach or detach a running container from a network:
docker network connect <your_network_name> <your_container_name>
docker network disconnect <your_network_name> <your_container_name>
Via Docker Compose
To join an existing external network in a docker-compose.yml:
services:
my-app:
image: my-image
container_name: my-app
restart: unless-stopped
networks:
- <your_network_name>
networks:
<your_network_name>:
external: true
external: true tells Compose the network already exists and should not be created automatically.
Expected Output
nginx-proxy → 172.18.0.2/16
backend-service → 172.18.0.3/16
other-container → 172.18.0.4/16
Explanation
--network <your_network_name>
Connects the container to the specified Docker network so it can reach other services by container name.
--restart unless-stopped
Automatically restarts the container on reboot or crash, unless manually stopped.
-p 80:80 / -p 443:443
Exposes HTTP and HTTPS ports from the container to the host.
-v .../conf.d:/etc/nginx/conf.d:ro
Mounts local Nginx virtual host configs as read-only inside the container.
-v .../proxy_params:/etc/nginx/proxy_params:ro
Mounts shared proxy header settings (e.g. X-Real-IP, X-Forwarded-For).
-v .../nginx-certs:/etc/nginx/certs:ro
Mounts SSL certificates directory as read-only for HTTPS support.
docker network inspect
Lists all containers connected to the network along with their assigned internal IP addresses.
Notes
Make sure the network exists before running the container:
docker network create <your_network_name>
Config files in conf.d must have a .conf extension to be picked up by Nginx automatically.
If Nginx fails to start, check config syntax with:
docker exec nginx-proxy nginx -t