- download these two files to the same directory
- docker-compose up
- http://localhost should show you "it works" which is apache being reverse-proxied through nginx
- docker sets up DNS for
web
based on compose service name so the nginx front-end can find http://web - proxy is set to listen on public port 80 on host so it'll receive incoming traffic, then push to httpd
-
-
Save BretFisher/468bca2900b90a4dddb7fe9a52143fc6 to your computer and use it in GitHub Desktop.
version: '3' | |
services: | |
proxy: | |
image: nginx:1.11 # this will use the latest version of 1.11.x | |
ports: | |
- '80:80' # expose 80 on host and sent to 80 in container | |
volumes: | |
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro | |
web: | |
image: httpd # this will use httpd:latest |
server { | |
listen 80; | |
location / { | |
proxy_pass http://web; | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Host $server_name; | |
} | |
} |
and sir how can combine docker-swarm with docker-compose
Hi Bret, I am getting the below error:
ERROR: for proxy Cannot start service proxy: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused "rootfs_linux.go:58: mounting \"/root/tmp/proxy/nginx.conf\" to rootfs \"/var/lib/docker/aufs/mnt/f6e22c98d09f14d4ed858153e1672d2de5b5e6ea09d46a092bb971cef41a6308\" at \"/var/lib/docker/aufs/mnt/f6e22c98d09f14d4ed858153e1672d2de5b5e6ea09d46a092bb971cef41a6308/etc/nginx/conf.d/default.conf\" caused \"not a directory\""": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.
Hi Bret, I am getting the below error:
ERROR: for proxy Cannot start service proxy: OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused "rootfs_linux.go:58: mounting "/root/tmp/proxy/nginx.conf" to rootfs "/var/lib/docker/aufs/mnt/f6e22c98d09f14d4ed858153e1672d2de5b5e6ea09d46a092bb971cef41a6308" at "/var/lib/docker/aufs/mnt/f6e22c98d09f14d4ed858153e1672d2de5b5e6ea09d46a092bb971cef41a6308/etc/nginx/conf.d/default.conf" caused "not a directory""": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.
This is because , maybe you are using a docker toolbox in windows. The following docker-compose.yml file contains the volumes.. which will only work with docker toolbox in windows ...only if you put the docker-compose.yml and nginx.conf inside the C:/Users// directory.
sir i want to use nginx as a load balancer and proxy server . so can i do this tasks with docker-compose..???
i'm just asking this because after running container with docker-compose they don't get and ip.!!