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

RemoveNonTaggedImages is not working because image gets latest tag when not specified #190

Closed
szczepq opened this issue May 21, 2021 · 6 comments
Assignees
Labels
under-investigation A investigation is made around the issue waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further.
Milestone

Comments

@szczepq
Copy link

szczepq commented May 21, 2021

I'm not specifying a tag for my image in docker-compose.yml

version: "3.4"

services:
  my-api:
    image: my.api
    build:
      context: my.API
      dockerfile: Dockerfile
    ports:
      - "5005:80"

After running builder with docker-compose.yml file like this

            _compositeService = new Builder()
                .UseContainer()
                .FromComposeFile(dockerComposePath)
                .RemoveOrphans()
                .RemoveNonTaggedImages()
                .ForceBuild()
                .WaitForHttp("my-api", $"{confirmUrl}/courses",
                    continuation: (response, _) => response.Code != HttpStatusCode.OK ? 5000 : 0)
                .Build()
                .Start();

my image my-api has tag latest

so RemoveNonTaggedImages() which is adding --rmi local to docker-compose down is not removing this image.

@mariotoffia mariotoffia self-assigned this May 21, 2021
@mariotoffia mariotoffia added this to the 4.0.0 milestone May 21, 2021
@mariotoffia
Copy link
Owner

Thanks for reporting this bug! - I'll have a check and a fix this weekend.

Cheers,
Mario

@mariotoffia
Copy link
Owner

It seems that docker-compose will automatically apply latest when not specified, hence as you state, it will not remove the image.

The only way I can think of is that you use:

_compositeService = new Builder()
                .UseContainer()
                .FromComposeFile(dockerComposePath)
                .RemoveOrphans()
                .RemoveAllImages()
                .ForceBuild()
                .WaitForHttp("my-api", $"{confirmUrl}/courses",
                    continuation: (response, _) => response.Code != HttpStatusCode.OK ? 5000 : 0)
                .Build()
                .Start();

Pleas let me know, if you got any other workaround.

Cheers,
Mario

@mariotoffia mariotoffia added the waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further. label May 21, 2021
@szczepq
Copy link
Author

szczepq commented May 24, 2021

It seems that docker-compose will automatically apply latest when not specified, hence as you state, it will not remove the image.

The only way I can think of is that you use:

_compositeService = new Builder()
                .UseContainer()
                .FromComposeFile(dockerComposePath)
                .RemoveOrphans()
                .RemoveAllImages()
                .ForceBuild()
                .WaitForHttp("my-api", $"{confirmUrl}/courses",
                    continuation: (response, _) => response.Code != HttpStatusCode.OK ? 5000 : 0)
                .Build()
                .Start();

Pleas let me know, if you got any other workaround.

Cheers,
Mario

I was using RemoveAllImages before I found ForceBuild which, in my case, is enough. I just need to rebuild my API image after fixing bugs discovered in the test project.

but docker-compose up from console is not adding latest tag

In few places in your code you are adding latest tag when it is not specified

Ductus.FluentDocker.Builders
...
public sealed class ImageBuilder
...
    public override IContainerImageService Build()
    {
      if (string.IsNullOrEmpty(_config.ImageName))
        throw new FluentDockerException("Cannot create or verify an image without a name");

      var host = FindHostService();
      if (!host.HasValue)
        throw new FluentDockerException(
          $"Cannot build Dockerfile for image {_config.ImageName} since no host service is defined");

      var tag = null == _config.Params.Tags ? "latest" : _config.Params.Tags[0];
      var image = host.Value.GetImages().FirstOrDefault(x => x.Name == _config.ImageName && x.Tag == tag);

      if (_config.VerifyExistence && null != image)
        return image;

      if (null == _config.Params.Tags)
        _config.Params.Tags = new[] { "latest" };

or

Ductus.FluentDocker.Commands
...
public static class Client
...
    public static CommandResponse<IList<string>> Build(this DockerUri host, string name, string tag, string workdir = null,
      ContainerBuildParams prms = null,
      ICertificatePaths certificates = null)
    {
      if (null == tag)
      {
        tag = "latest";

@mariotoffia
Copy link
Owner

@szczepanbh Yes, that is true that I do add tags to images when using standard docker client build. However, as you use the docker-compose it will not execute any of those commands instead it will do a ComposeUp command in the Compose.cs.

In essense, if you'd do a docker-compose up in your folder (manually using docker-compose command) it will automatically add latest. I think (?) this has been changed from earlier where you had to explicitly specify a tag.

If you have any insights or tips of how to use docker-compose without it auto-apply latest, I would be super happy to incorporate that into the library.

Cheers,
Mario :)

@mariotoffia mariotoffia added under-investigation A investigation is made around the issue and removed bug labels May 25, 2021
@szczepq
Copy link
Author

szczepq commented May 25, 2021

You are right @mariotoffia docker-compose up assigns latest tag. I don't know and I wasn't able to find the way to force docker-compose not to add this tag. So wired when you have --rmi local as an option.

@mariotoffia
Copy link
Owner

@szczepanbh I'm closing this for now, if you come across a way to not applying label., please let me know so I can incorporate that.

Cheers,
Mario :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
under-investigation A investigation is made around the issue waiting-for-feedback Waiting for someone to give feedback until this issue can be brought further.
Projects
None yet
Development

No branches or pull requests

2 participants