Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-23704

Control over ports with docker build steps

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      There doesn't appear to be any hooks in the plugin to explicitly control what ports are exposed to the host and what port mapping should be taken when issuing a "docker run" command.

      Need ability both map an exposed port to a fixed port on the host, as well as capture a auto generated host port in an environment variable to pass to the running build.

        Attachments

          Activity

          Hide
          simic Simic Zhang added a comment -

          Hi Vojtech Juranek,
          please kindly inform how could I create a container by mapping container port 8080 to host port 80.Should I pass environment variables like "DOCKER_HOST_BIND_PORTS=8080, DOCKER_HOST_PORT_TCP_80=8080"? Although it seems not working for my case...

          Best regards,
          Simic Zhang

          Show
          simic Simic Zhang added a comment - Hi Vojtech Juranek, please kindly inform how could I create a container by mapping container port 8080 to host port 80.Should I pass environment variables like "DOCKER_HOST_BIND_PORTS=8080, DOCKER_HOST_PORT_TCP_80=8080"? Although it seems not working for my case... Best regards, Simic Zhang
          Hide
          vjuranek vjuranek added a comment -

          thanks. OK, closing then

          Show
          vjuranek vjuranek added a comment - thanks. OK, closing then
          Hide
          albers Harald Albers added a comment -

          Thanks, DOCKER_HOST_PORT_$SCHEMA_$PORT is exactly what I need.
          There is an issue with env resolution, though, see https://github.com/jenkinsci/docker-build-step-plugin/pull/11

          Show
          albers Harald Albers added a comment - Thanks, DOCKER_HOST_PORT_$SCHEMA_$PORT is exactly what I need. There is an issue with env resolution, though, see https://github.com/jenkinsci/docker-build-step-plugin/pull/11
          Hide
          vjuranek vjuranek added a comment -

          Hi,
          I added two evn. variables:
          DOCKER_HOST_BIND_PORTS - containes comma separated list of ports to which are bound docker container ports
          DOCKER_HOST_PORT_$SCHEMA_$PORT - which docker conatiner port is bound to this port (e.g. DOCKER_HOST_PORT_TCP_80 would conatin value 8080 in case that conatiner port 8080 is bound to port 80 on host)

          Is this what you need? Any suggestion before I release it what to better, to be more user friendly?
          Thanks

          Show
          vjuranek vjuranek added a comment - Hi, I added two evn. variables: DOCKER_HOST_BIND_PORTS - containes comma separated list of ports to which are bound docker container ports DOCKER_HOST_PORT_$SCHEMA_$PORT - which docker conatiner port is bound to this port (e.g. DOCKER_HOST_PORT_TCP_80 would conatin value 8080 in case that conatiner port 8080 is bound to port 80 on host) Is this what you need? Any suggestion before I release it what to better, to be more user friendly? Thanks
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Vojtech Juranek
          Path:
          src/main/java/org/jenkinsci/plugins/dockerbuildstep/DockerEnvContributor.java
          src/main/java/org/jenkinsci/plugins/dockerbuildstep/action/EnvInvisibleAction.java
          http://jenkins-ci.org/commit/docker-build-step-plugin/bd510236b553a6158d16babfb83d4913e5637f46
          Log:
          JENKINS-23704 Expose port binding as env. variables

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Vojtech Juranek Path: src/main/java/org/jenkinsci/plugins/dockerbuildstep/DockerEnvContributor.java src/main/java/org/jenkinsci/plugins/dockerbuildstep/action/EnvInvisibleAction.java http://jenkins-ci.org/commit/docker-build-step-plugin/bd510236b553a6158d16babfb83d4913e5637f46 Log: JENKINS-23704 Expose port binding as env. variables
          Hide
          albers Harald Albers added a comment -

          I just started to work on the help file for StartCommand's portBindings field.

          I found the snytax quite confusing because it is different form the syntax of the docker program. In particular, it reverses argument order:

          docker run -p Port bindings field
          80:8080 8080 80
          127.0.0.1:80:8080/tcp 8080/tcp 127.0.0.1:80

          I suggest to use the Docker CLI syntax here, optionally allowing white space instead of a colon as the delimiter between host and container part of each binding definition.

          @vjuranek If you agree, I'd be happy to create a PR implementing that.

          Show
          albers Harald Albers added a comment - I just started to work on the help file for StartCommand 's portBindings field. I found the snytax quite confusing because it is different form the syntax of the docker program. In particular, it reverses argument order: docker run -p Port bindings field 80:8080 8080 80 127.0.0.1:80:8080/tcp 8080/tcp 127.0.0.1:80 I suggest to use the Docker CLI syntax here, optionally allowing white space instead of a colon as the delimiter between host and container part of each binding definition. @vjuranek If you agree, I'd be happy to create a PR implementing that.
          Hide
          vjuranek vjuranek added a comment -

          Reopening - I forgot to implement exporting ports as evn. vars.

          Show
          vjuranek vjuranek added a comment - Reopening - I forgot to implement exporting ports as evn. vars.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Vojtech Juranek
          Path:
          src/main/java/org/jenkinsci/plugins/dockerbuildstep/cmd/StartCommand.java
          http://jenkins-ci.org/commit/docker-build-step-plugin/37aab429b6eeff9e29185a5c37885df18a00c9c0
          Log:
          [FIXED JENKINS-23704] Allow specify port binding when starting the container

          Compare: https://github.com/jenkinsci/docker-build-step-plugin/compare/a8b40740b672...37aab429b6ee

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Vojtech Juranek Path: src/main/java/org/jenkinsci/plugins/dockerbuildstep/cmd/StartCommand.java http://jenkins-ci.org/commit/docker-build-step-plugin/37aab429b6eeff9e29185a5c37885df18a00c9c0 Log: [FIXED JENKINS-23704] Allow specify port binding when starting the container Compare: https://github.com/jenkinsci/docker-build-step-plugin/compare/a8b40740b672...37aab429b6ee

            People

            • Assignee:
              vjuranek vjuranek
              Reporter:
              mphilpot Mark Philpot
            • Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: