Skip to content

Image and build together#2458

Merged
aanand merged 2 commits into
docker:masterfrom
dnephin:image_and_build_together
Jan 12, 2016
Merged

Image and build together#2458
aanand merged 2 commits into
docker:masterfrom
dnephin:image_and_build_together

Conversation

@dnephin
Copy link
Copy Markdown

@dnephin dnephin commented Nov 25, 2015

Fixes #2092

Allow both image and build in a service config, and use image as the image name when building, if it exists.

@dnephin
Copy link
Copy Markdown
Author

dnephin commented Jan 12, 2016

Rebased, now only applies to V2 config.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
@dnephin dnephin force-pushed the image_and_build_together branch from ce352ce to e98ab0e Compare January 12, 2016 19:10
@aanand
Copy link
Copy Markdown

aanand commented Jan 12, 2016

LGTM

aanand added a commit that referenced this pull request Jan 12, 2016
@aanand aanand merged commit 0c626e6 into docker:master Jan 12, 2016
@dnephin dnephin deleted the image_and_build_together branch January 12, 2016 21:10
@graingert
Copy link
Copy Markdown

@dnephin does this allow something like:

# docker-compose.yml
production:
   - image: ham/spam
   - build: ./spam
development:
   - image: ham/spam-dev
   - build: ./spam
   - dockerfile: Dockerfile-dev
# spam/Dockerfile
FROM ubuntu
RUN apt-get install nginx npm
COPY . /usr/bin/src/
RUN npm build
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
# spam/Dockerfile-dev
FROM ham/spam # build on parent ham/spam.
RUN npm start # start live reloader

@aanand
Copy link
Copy Markdown

aanand commented Jan 28, 2016

@graingert Yes, but you have to use the v2 file format to use image and build together:

version: 2
services:
  production:
    image: ham/spam
    build: ./spam
  development:
    image: ham/spam-dev
    build:
      context: ./spam
      dockerfile: Dockerfile-dev

You probably wouldn't actually define development and production as separate services in the same file, though. More likely you'd put the core config in docker-compose.yml and the development override in docker-compose.override.yml:

# docker-compose.yml
version: 2
services:
  spam:
     image: ham/spam
     build: ./spam

# docker-compose.override.yml
version: 2
services:
  spam:
    image: ham/spam-dev
    build:
      context: ./spam
      dockerfile: Dockerfile-dev

@graingert
Copy link
Copy Markdown

@aanand How does docker-compose know it needs to build "ham/spam" for docker-compose.override.yml's Dockerfile-dev to work?

@aanand
Copy link
Copy Markdown

aanand commented Jan 28, 2016

I see what you were getting at now. Compose doesn't support dependent builds - you should use a tool like Shipwright for that.

@graingert
Copy link
Copy Markdown

@aanand ah nice, thanks

@dnephin
Copy link
Copy Markdown
Author

dnephin commented Jan 28, 2016

I've been prototyping a tool in https://github.com/dnephin/dobi that would support building chains of images (as well as a bunch of other things). There are a few docs and examples, but it could definitely use more, I need one for the ordered build use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants