title: How to expose a container port outside of docker/container using docker-compose?
body: <p>I have a container that it has several ports, I want to have access to one of its ports (<code>9001</code>) outside of this docker as remote.</p>
  
  <ul>
  <li>My docker IP is: <code>172.17.0.1</code></li>
  <li>My container IP is: <code>172.19.0.23</code></li>
  <li>My server IP is: <code>192.168.1.131</code></li>
  </ul>
  
  <hr>
  
  <p>I have searched about that and I found <code>expose port</code> keyword, and I did it but not worked.</p>
  
  <blockquote>
    <p>How to expose docker ports to make your containers externally accessible<br>
    <a href="https://bobcares.com/blog/docker-port-expose/" rel="noreferrer">Reference</a></p>
  </blockquote>
  
  <hr>
  
  <h1>This is my docker-compose file:</h1>
  
  <pre><code>version: '3'
  
  services:
    nginx:
        image: nginx:latest
        container_name: nginx
        ports:
          - "8010:8010"
  
        volumes:
          - .:/code
          - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
  
        links:
          - ivms
  
        restart: unless-stopped
  
    ivms:
        build: .
        container_name: ivms
        command: bash bashes/createDB.sh
        volumes:
          - .:/code
        expose:
          - "8010"
          - "9001"  # exposed disired port
        ports:
          - "9001:9001"
  </code></pre>
  
  <hr>
  
  <p>I run above docker-compose file with: <code>$ docker-compose up -d</code></p>
  
  <ul>
  <li>But when I using <strong><code>server_IP:9001 --&gt; 192.168.1.131:9001</code></strong> or
  <strong><code>docker_IP:9001 --&gt; 172.17.0.1:9001</code></strong> can not access to that (in remote or local mode)</li>
  <li>But when using <strong><code>container_IP:9001 --&gt; 172.19.0.23:9001</code></strong> this
  works in local.</li>
  </ul>
  
  <p>What should I do that I can access to <strong><code>server_IP:9001 --&gt; 192.168.1.131:9001</code></strong>?</p>
  
  <hr>
  
  <p>[<strong>NOTE</strong>]:  </p>
  
  <ul>
  <li><p>In <code>createDB.sh</code> runs several operations such as creating a <strong>ZMQ on
  <code>9001</code> port</strong>.</p></li>
  <li><p>I have been set the port allowing before, using <code>$ ufw allow 9001</code></p></li>
  <li>I tried on Ubuntu 16.04 and Ubuntu-Server 16.04</li>
  </ul>
  
  <hr>
  
  <p>Any help would be appreciated.</p>