Build with Compose
Files
~> ls
html/ docker-compose.yml nginx.conf nginx.Dockerfile
docker-compose.yml
- Docker first checks if I have the specified
image
in my cache - If not found, it will use Dockerfile specified in
build
version: '2'
# based off NGINX proxy example, only we build nginx.conf into image
# uses sample site from https://startbootstrap.com/template-overviews/agency/
services:
proxy:
build:
context: .
dockerfile: nginx.Dockerfile
image: nginx-custom
ports:
- '80:80'
web:
image: httpd
volumes:
- ./html:/usr/local/apache2/htdocs/
nginx.conf
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;
}
}
nginx.Dockerfile
FROM nginx:1.11
COPY nginx.conf /etc/nginx/conf.d/default.conf
html folder containing site --- this is omitted in this example, just know, it is there (standard webpage with html,css,js,php, etc.)
Output
~> docker-compose up
Creating network "composesample3_default" with the default driver
Building proxy
Step 1/2 : FROM nginx:1.11
---> 5766334bdaa0
Step 2/2 : COPY nginx.conf /etc/nginx/conf.d/default.conf
---> b2ed8d436fc3
Removing intermediate container a3d093c94ea2
Successfully built b2ed8d436fc3
Successfully tagged nginx-custom:latest
WARNING: Image for service proxy was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating composesample3_proxy_1 ...
Creating composesample3_web_1 ...
Creating composesample3_proxy_1
Creating composesample3_web_1 ... done
Attaching to composesample3_proxy_1, composesample3_web_1
...
Gracefully stopping... (press Ctrl+C again to force)
Stopping composesample3_web_1 ... done
Stopping composesample3_proxy_1 ... done
~> docker-compose down
Removing composesample3_web_1 ... done
Removing composesample3_proxy_1 ... done
Removing network composesample3_default
~> docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-custom latest b2ed8d436fc3 2 minutes ago 183MB