title: How to run web server docker container in Azure devops pipeline and HTTP access it?
body: <p>Please help understand the cause and solution for the issue in Azure Devops pipeline.</p>
  <p>Trying to run a docker container which runs a web server inside inside a Azure devops pipeline as a step.</p>
  <pre><code>docker pull ${CONTAINER_IMAGE}
  
  CONTAINER_ID=$(docker run -d --rm \
    --cidfile cid.log \
    -p 108080:8080 \
    ${CONTAINER_IMAGE}
  )
  echo &quot;container id is ${CONTAINER_ID}&quot;
  docker ps
  
  echo &quot;--------------------------------------------------------------------------------&quot;
  echo &quot;docker container ip&quot;
  IPS=$(docker container inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' ${CONTAINER_ID})
  HOST=$(echo ${IPS[0]} | xargs)
  echo $HOST
  
  echo &quot;--------------------------------------------------------------------------------&quot;
  echo &quot;Testing web /health response from the container...&quot;
  curl -v http://${HOST}:8080/health
  </code></pre>
  <p>When run on a laptop, it works.</p>
  <pre><code>pulling the container image ****
  ...
  Digest: sha256:9edc6a55118f0909cf7120a53837ae62b8e65154bc30b89630f4f82bc0c4add7
  ...
  **Starting the container ****...
  container id is 088a28329d236582f0757862cb5bba2172ddb40c3315394db11ab39265f155b3
  
  CONTAINER ID   IMAGE                                                                                               COMMAND                  CREATED         STATUS         PORTS                     NAMES
  088a28329d23   ****   &quot;/bin/sh -c 'gunicor…&quot;   6 seconds ago   Up 5 seconds   0.0.0.0:18080-&gt;8080/tcp   quirky_murdock
  ccfc76e321aa   gcr.io/inverting-proxy/agent                                                                        &quot;/bin/sh -c '/opt/bi…&quot;   5 minutes ago   Up 5 minutes                             proxy-agent
  --------------------------------------------------------------------------------
  docker container ip
  172.17.0.2
  
  --------------------------------------------------------------------------------
  Testing web /health response from the container...
  * Expire in 0 ms for 6 (transfer 0x55c1870780f0)
  *   Trying 172.17.0.2...
  * TCP_NODELAY set
  * Expire in 200 ms for 4 (transfer 0x55c1870780f0)
  * Connected to 172.17.0.2 (172.17.0.2) port 8080 (#0)
  &gt; GET /health HTTP/1.1
  &gt; Host: 172.17.0.2:8080
  &gt; User-Agent: curl/7.64.0
  &gt; Accept: */*
  &gt; 
  &lt; HTTP/1.1 200 OK
  &lt; Server: gunicorn
  &lt; Date: Mon, 08 Aug 2022 06:44:12 GMT
  &lt; Connection: close
  &lt; Content-Type: application/json
  &lt; Content-Length: 0
  &lt; 
  * Closing connection 0**
  </code></pre>
  <p>However, it does not work in Azure DevOps CI pipeline.</p>
  <pre><code>++ docker run -d --rm --cidfile cid.log -p 18080:8080 *****
  + CONTAINER_ID=9c0f7c528b979651079d9f066c80cb9a26ec1af18415a0df5d269d252dfad0cb
  + echo 'container id is 9c0f7c528b979651079d9f066c80cb9a26ec1af18415a0df5d269d252dfad0cb'
  container id is 9c0f7c528b979651079d9f066c80cb9a26ec1af18415a0df5d269d252dfad0cb
  + echo --------------------------------------------------------------------------------
  + echo 'listing docker processes...'
  + docker ps
  --------------------------------------------------------------------------------
  listing docker processes...
  CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
  + echo --------------------------------------------------------------------------------
  --------------------------------------------------------------------------------
  docker container ip
  + echo 'docker container ip'
  + docker container inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' 9c0f7c528b979651079d9f066c80cb9a26ec1af18415a0df5d269d252dfad0cb
  
  Error: No such container: 9c0f7c528b979651079d9f066c80cb9a26ec1af18415a0df5d269d252dfad0cb
  </code></pre>
  <h1>Related issues</h1>
  <p>There is an issue reported.</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/52166372/cannot-conect-to-docker-container-running-in-vsts">Cannot conect to Docker container running in VSTS</a></li>
  </ul>
  <blockquote>
  <p>The problem is that the VSTS build agent runs in a Docker container. When the Docker container for Apache is started, it runs on the same level as the VSTS build agent Docker container, not nested inside the VSTS build agent Docker container.<br />
  There are two possible solutions:</p>
  <ul>
  <li>Replacing localhost with the ip address of the docker host, keeping the port number 8083</li>
  <li>Replacing localhost with the ip address of the docker container, changing the host port number 8083 to the container port number 80.</li>
  </ul>
  </blockquote>
  <p>Followed the solution as in the code above but did not work.</p>