Build with Compose

Files

~> ls
html/ docker-compose.yml nginx.conf nginx.Dockerfile
  • 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/

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

Last updated

Was this helpful?