sbt-docker icon indicating copy to clipboard operation
sbt-docker copied to clipboard

Configure dockerPush to use a private registry instead of docker.io

Open ankitkariryaa opened this issue 8 years ago • 7 comments

Currently to push to a private repository, I append the registry in frontend of the images name like: myregistry/project1/target1:version. It will be useful to have an option to configure the registry to push to (that is appended in front of the name at time of push). This problem could also be solved by allowing multiple tags based upon some settings( for example registry ) and allowing to push only the selected tag(s). For example:
ImageName("localRegistry",s"$dockerRegistry/$project/$name:v${version.value}"), ImageName("default",s"$project/$name:v${version.value}")

and then allowing sbt target/dockerBuildAndPush localRegistry

ankitkariryaa avatar Sep 21 '16 13:09 ankitkariryaa

I want to more about the use case for this. When do you need a different name for your image locally and in the registry?

marcus-drake avatar Sep 21 '16 22:09 marcus-drake

We create multiple images but only some are pushed to the an open registry(lets say docker.io). But each image can/should be pushed to a local private registry. The main difference between naming in the two is that, in the local registry we have detailed versions (dirty versions with hashes), whereas in the global one the versions are simplified.

ankitkariryaa avatar Sep 22 '16 08:09 ankitkariryaa

If there is interest from others on a feature to support this then we could perhaps add it. But in the mean time it is probably sufficient for you to create a custom task that calls sbtdocker.DockerPush or that runs the docker push command directly with the images that you want to push. Or you could perhaps dynamically add the image names for the open registry to the imageNames in docker setting when you want to release to your images.

marcus-drake avatar Sep 25 '16 12:09 marcus-drake

+1

austek avatar Oct 28 '17 11:10 austek

Probably too late, but +1

e-kolpakov avatar Apr 18 '18 12:04 e-kolpakov

+1 as well

MartinSeeler avatar Jun 28 '18 13:06 MartinSeeler

After re-reading this I'm unsure if this is a problem. It might be as easy to just set the exact names you want the image to be tagged with in the key imageNames in docker. If not please provide an example to help me understand.

If you want completely custom behavior you can create your own sbt task which can push whatever you want it to push:

  import sbtdocker._
  val customDockerPush = taskKey[Unit]("My custom docker push task")
  customDockerPush := {
      val log = Keys.streams.value.log
      val dockerPath = (DockerKeys.dockerPath in docker).value
      val imageNames = Seq(ImageName("my-org/my-fancy-image:verion"))

      DockerPush(dockerPath, imageNames, log)
    }

and then just call it sbt customDockerPush.

marcus-drake avatar Jun 28 '18 18:06 marcus-drake