- 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
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; | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
pankajred
commented
Sep 13, 2017
and sir how can combine docker-swarm with docker-compose |
This comment has been minimized.
This comment has been minimized.
sarashmishra
commented
Jun 7, 2018
Hi Bret, I am getting the below error: |
This comment has been minimized.
This comment has been minimized.
jchowdhary
commented
Sep 13, 2018
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. |
This comment has been minimized.
pankajred commentedSep 13, 2017
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.!!