Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --build and --no-build options to run analogous to up command. #3448

Closed
nhooey opened this issue May 11, 2016 · 17 comments
Closed

Add --build and --no-build options to run analogous to up command. #3448

nhooey opened this issue May 11, 2016 · 17 comments
Labels

Comments

@nhooey
Copy link

nhooey commented May 11, 2016

docker-compose up --help outputs:

    --no-build                 Don't build an image, even if it's missing.
    --build                    Build images before starting containers.

But these options are missing from docker-compose run --help.

As of docker-compose version 1.7.1, build unknown from Pip.

@shin-
Copy link

shin- commented May 11, 2016

Can't you just run docker-compose build first?

@nhooey
Copy link
Author

nhooey commented May 11, 2016

No, because it will build every single thing in the docker-compose.yml file, and even when cached, this process is very slow. docker-compose run --build should detect what needs to be built and only build those.

@shin-
Copy link

shin- commented May 11, 2016

build takes a service argument, i.e. docker-compose build foo will only build the foo service.

@nhooey
Copy link
Author

nhooey commented May 11, 2016

I know how it works.

But I want docker-compose to do the most intelligent thing, and rebuild whatever services and dependencies are involved.

If docker-compose up --build exists, then docker-compose run --build should also exist.

@christianbundy
Copy link

If docker-compose up --build exists, then docker-compose run --build should also exist.

Exactly, the "run docker-compose build first" argument is equally valid with respect to docker-compose up --build too. It's confusing that I can run docker-compose up --build django to start my server, but I have to run docker-compose build && docker-compose run django test to run my tests. Is there any reason to reject this functionality that wouldn't apply equally to docker-compose up --build?

I'm open to either requiring docker-compose build everywhere or allowing --build everywhere, but we should have consistency throughout the command-line API. Thanks for you work in maintaining this project.

@shin- shin- closed this as completed Nov 6, 2018
@daaain
Copy link

daaain commented Jan 17, 2019

Why was this issue closed without a comment?

I would find --no-build especially helpful to prevent build triggered by a run as that won't have the necessary build ARG values passed and fail.

@jaysonsantos
Copy link

Hey there, I also came looking for something like this for builds with ARG.
In my case, the first build injects some sutff into the image which is actually needed but on run there would be no need to inject/build it as the image is with the right data otherwise I would have to export the used variables on every usage of docker-compose run

@nhooey
Copy link
Author

nhooey commented Jul 20, 2019

@ulyssessouza Could you re-open this?

@ulyssessouza ulyssessouza reopened this Jul 22, 2019
@stale
Copy link

stale bot commented Jan 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 18, 2020
@stale
Copy link

stale bot commented Jan 25, 2020

This issue has been automatically closed because it had not recent activity during the stale period.

@stale stale bot closed this as completed Jan 25, 2020
@ZimbiX
Copy link

ZimbiX commented Feb 4, 2020

Please reopen

@muellermichel
Copy link

I would find --no-build especially helpful to prevent build triggered by a run as that won't have the necessary build ARG values passed and fail.

This is exactly what bugs me at the moment too.

@superlevure
Copy link

Can we please re-open this ?

@fzieris
Copy link

fzieris commented Feb 17, 2021

I would find --no-build especially helpful to prevent build triggered by a run as that won't have the necessary build ARG values passed and fail.

This is exactly what bugs me at the moment too.

Same here. My workaround: Check for an existing docker image and, if necessary, build it with the right arguments before calling run:

# Assuming project 'my_project' and service 'app'

if ! docker inspect --type=image my_project_app:latest > /dev/null 2>&1
then
    echo "Couldn't find image for 'app'. Going to build it first."
    docker-compose build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -u) app

    # Or put any other logic you would execute in the --no-build case here.
fi

# Now we can call `run` with a properly built image
docker-compose run --no-deps --rm app run-tests-or-whatever.sh

@adaamz
Copy link

adaamz commented Mar 22, 2021

Also it is usefull when you have image in registry but don't have locally - it rather builds than pull image, which is not what I want.

eg.

services:
    asdf:
        image: my-registry.com/my-image:my-tag
        build: .
docker-compose run --rm asdf  # slowly builds image instead of fast pull

@ginjo
Copy link

ginjo commented Apr 1, 2022

Also it is usefull when you have image in registry but don't have locally - it rather builds than pull image, which is not what I want.

This is exactly what's tripping me up too. Really need a --no-build for docker-compose run, or even more generally for docker-compose.

@victorm1710
Copy link

As a workaround you can use docker compose pull before docker compose run, as soon as necessary images are present locally, compose doesn't build images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests