title: Connection refused trying to connect spring boot application in docker
body: <p>I try to run spring boot application in Docker, Circle CI. Please, check how my .circleci/config.yml file looks like:</p>
  <pre class="lang-yaml prettyprint-override"><code>version: 2.1
  
  jobs:
  
    test:
      docker:
        - image: maven:3.8.5-openjdk-17-slim
  
      environment:
        CHROMEDRIVER_VERSION: 100.0.4896.60
        CHROMEDRIVER_DIR: /tmp/chromedriver/
        WIKI_ENV: CIRCLE_CI
  
      steps:
        - checkout
        - run:
            name: &quot;Install gnupg2, wget, xvfb and unzip&quot;
            command: |
              apt-get update
              apt-get install -y gnupg2
              apt-get install -y wget xvfb unzip
        - run:
            name: &quot;Install Chrome Browser&quot;
            command: |
              wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
              echo &quot;deb http://dl.google.com/linux/chrome/deb/ stable main&quot; &gt;&gt; /etc/apt/sources.list.d/google.list
              apt-get update -y
              apt-get install -y google-chrome-stable
        - run:
            name: &quot;Setup chromedriver&quot;
            command: |
              mkdir -p $CHROMEDRIVER_DIR
              wget -q --continue -P $CHROMEDRIVER_DIR &quot;http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip&quot;
              unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR
              export PATH=$CHROMEDRIVER_DIR:$PATH
        - run:
            name: &quot;Build jar&quot;
            command: mvn clean package spring-boot:repackage
        - run:
            name: &quot;Start&quot;
            command: mvn spring-boot:start
        - run:
            name: &quot;Check&quot;
            command: curl http://localhost:8080
  
        - store_test_results:
            path: target/surefire-reports/junitreports
  
        - store_artifacts:
            path: target/surefire-reports/junitreports
  
        - store_artifacts:
            path: target/screenshots
  
  workflows:
    default:
      jobs:
        - test
  </code></pre>
  <p>A pipeline fails on a &quot;Check&quot; step with the <code>curl: (7) Failed to connect to localhost port 8080: Connection refused</code> error.</p>
  <p>Here is the output of the &quot;Start&quot; step:</p>
  <pre class="lang-sh prettyprint-override"><code>[INFO] Scanning for projects...
  [WARNING] 
  [WARNING] Some problems were encountered while building the effective model for vznd:selenium:jar:1.0
  [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.testng:testng:jar -&gt; duplicate declaration of version ${testng.version} @ line 54, column 21
  [WARNING] 
  [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
  [WARNING] 
  [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
  [WARNING] 
  [INFO] 
  [INFO] ---------------------------&lt; vznd:selenium &gt;----------------------------
  [INFO] Building selenium 1.0
  [INFO] --------------------------------[ jar ]---------------------------------
  [INFO] 
  [INFO] --- spring-boot-maven-plugin:2.6.3:start (default-cli) @ selenium ---
  [INFO] Attaching agents: []
  18:36:09.878 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@2c5fa29b
  
    .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::                (v2.6.3)
  
  2022-05-05 18:36:10.165  INFO 4520 --- [  restartedMain] vznd.selenium.SeleniumApp                : Starting SeleniumApp using Java 17.0.2 on aeadb1d9da7e with PID 4520 (/root/project/target/classes started by root in /root/project)
  2022-05-05 18:36:10.166  INFO 4520 --- [  restartedMain] vznd.selenium.SeleniumApp                : No active profile set, falling back to default profiles: default
  2022-05-05 18:36:10.239  INFO 4520 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
  2022-05-05 18:36:10.239  INFO 4520 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
  2022-05-05 18:36:11.021  INFO 4520 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
  2022-05-05 18:36:11.034  INFO 4520 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
  2022-05-05 18:36:11.035  INFO 4520 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.56]
  2022-05-05 18:36:11.086  INFO 4520 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2022-05-05 18:36:11.086  INFO 4520 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 846 ms
  2022-05-05 18:36:11.320  INFO 4520 --- [  restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
  2022-05-05 18:36:11.418  INFO 4520 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
  2022-05-05 18:36:11.459  INFO 4520 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
  2022-05-05 18:36:11.468  INFO 4520 --- [  restartedMain] vznd.selenium.SeleniumApp                : Started SeleniumApp in 1.58 seconds (JVM running for 2.136)
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD SUCCESS
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time:  3.129 s
  [INFO] Finished at: 2022-05-05T18:36:11Z
  [INFO] ------------------------------------------------------------------------
  </code></pre>
  <p>Here is my pom.xml:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
           xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.6.3&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;groupId&gt;vznd&lt;/groupId&gt;
      &lt;artifactId&gt;selenium&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
  
      &lt;properties&gt;
          &lt;maven.compiler.source&gt;17&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;17&lt;/maven.compiler.target&gt;
          &lt;maven-surefire-plugin.version&gt;3.0.0-M6&lt;/maven-surefire-plugin.version&gt;
          &lt;testng.version&gt;7.5&lt;/testng.version&gt;
          &lt;selenium-java.version&gt;3.141.59&lt;/selenium-java.version&gt;
          &lt;commons-io.version&gt;2.11.0&lt;/commons-io.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.testng&lt;/groupId&gt;
              &lt;artifactId&gt;testng&lt;/artifactId&gt;
              &lt;version&gt;${testng.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.testng&lt;/groupId&gt;
              &lt;artifactId&gt;testng&lt;/artifactId&gt;
              &lt;version&gt;${testng.version}&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
              &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
              &lt;version&gt;${selenium-java.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-io&lt;/groupId&gt;
              &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
              &lt;version&gt;${commons-io.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${maven-surefire-plugin.version}&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;systemPropertyVariables&gt;
                          &lt;webdriver.chrome.driver&gt;/tmp/chromedriver/chromedriver&lt;/webdriver.chrome.driver&gt;
                      &lt;/systemPropertyVariables&gt;
                      &lt;suiteXmlFiles&gt;
                          &lt;suiteXmlFile&gt;testng.xml&lt;/suiteXmlFile&gt;
                      &lt;/suiteXmlFiles&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>When I run this commands locally - it works. When it executes on CI - it fails. What I tried to fix:</p>
  <ol>
  <li>Run <code>java -jar target/selenium.jar &amp;</code> command on the &quot;Start&quot; step</li>
  <li>Run <code>mvn spring-boot:run &amp;</code> command instead of &quot;Build jar&quot; and &quot;Start&quot; steps</li>
  <li>Run <code>nohup mvn spring-boot:run &amp;</code> command instead of &quot;Build jar&quot; and &quot;Start&quot; steps</li>
  <li>Add <code>sleep 120</code> step after the &quot;Start&quot; step</li>
  </ol>
  <p>Could you please advise me what I am doing wrong?</p>