Answers: <p>Your mistake is that you are did not register the <em>app</em> service on the <em>app-net</em> network. To allow containers to connect with one another, they have to share a network and then use the image name as the domain name. Docker provides a network internal DNS service.</p>
  
  <pre><code>version: '3'
  services:
    couchdb:
      image: couchdb:latest
      restart: always
      volumes:
        - couchdb-data-volume:/usr/local/var/lib/couchdb
      env_file: .env.docker
      ports:
        - "12345:5986"
      networks:
        app-net:
  
    app:
      build: .
      image: app
      container_name: app
      restart: always
      depends_on:
        - couchdb
      env_file: .env.docker  
      networks:
        - app-net
  
  volumes:
    couchdb-data-volume:
  
  networks:
    app-net:
  </code></pre>
  
  <p>The URL from the <em>app</em> to the <em>couchdb</em> service would be <code>http://couchdb:5986</code>. To test this, open bash inside the <em>app</em> service with <code>docker exec -it app</code>. This depends on the <em>container_name</em> setting.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-14T23:13:57.747Z
Answers: 2018-02-14T23:13:57.747Z
Answers: Moritz
Body: <p>I am trying to connect to couchdb through the container but my app is not seeing it.</p>
  
  <p>However if I use the external address <code>123.456.789.123:12345</code> (<code>server_ip:external_port</code>) 
  it works but I need a connection through network with the internal port <code>5986</code>.</p>
  
  <p><strong>Docker-Compose.yml</strong></p>
  
  <pre><code>version: '3'
      services:
        couchdb:
          image: couchdb:latest
          restart: always
          volumes:
            - couchdb-data-volume:/usr/local/var/lib/couchdb
          env_file: .env.docker
          ports:
            - "12345:5986"
          networks:
            app-net:
              aliases:
                - couchdb
        app:
          build: .
          image: app
          restart: always
          depends_on:
            - couchdb
          env_file: .env.docker  
      networks:
        app-net:
          driver: bridge
      volumes:
        couchdb-data-volume:
  </code></pre>
  
  <p><strong>ENV FILE</strong></p>
  
  <pre><code>NODE_ENV=production
  COUCHDB_SERVER=http://user:pass@couchdb:5986
  COUCHDB_USER=user
  COUCHDB_PASSWORD=pass
  </code></pre>
  
  <p>I Also tried links instead of networks but the same issue.</p>
  
  <pre><code> links:
   - couchdb
  </code></pre>
  
  <p>Any Ideas ?</p>
  
Tags: <docker><containers><docker-compose>
Title: Docker Compose V3 app container can't access couchdb container
UserDisplayName: Anouar Kacem
ThreadText: # Docker Compose V3 app container can't access couchdb container
  
  (Asked by: username_0 on 2018-02-14)
  
  I am trying to connect to couchdb through the container but my app is not seeing it.
  
  However if I use the external address `123.456.789.123:12345` (`server_ip:external_port`)
  it works but I need a connection through network with the internal port `5986`.
  
  **Docker-Compose.yml**
  
  ```
  version: '3'
      services:
        couchdb:
          image: couchdb:latest
          restart: always
          volumes:
            - couchdb-data-volume:/usr/local/var/lib/couchdb
          env_file: .env.docker
          ports:
            - "12345:5986"
          networks:
            app-net:
              aliases:
                - couchdb
        app:
          build: .
          image: app
          restart: always
          depends_on:
            - couchdb
          env_file: .env.docker  
      networks:
        app-net:
          driver: bridge
      volumes:
        couchdb-data-volume:
  
  ```
  
  **ENV FILE**
  
  ```
  NODE_ENV=production
  COUCHDB_SERVER=http://user:pass@couchdb:5986
  COUCHDB_USER=user
  COUCHDB_PASSWORD=pass
  
  ```
  
  I Also tried links instead of networks but the same issue.
  
  ```
   links:
   - couchdb
  
  ```
  
  Any Ideas ?
  
  **Tags:** docker, containers, docker-compose
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-02-14. Score: 1 | Accepted answer
  
  Your mistake is that you are did not register the *app* service on the *app-net* network. To allow containers to connect with one another, they have to share a network and then use the image name as the domain name. Docker provides a network internal DNS service.
  
  ```
  version: '3'
  services:
    couchdb:
      image: couchdb:latest
      restart: always
      volumes:
        - couchdb-data-volume:/usr/local/var/lib/couchdb
      env_file: .env.docker
      ports:
        - "12345:5986"
      networks:
        app-net:
  
    app:
      build: .
      image: app
      container_name: app
      restart: always
      depends_on:
        - couchdb
      env_file: .env.docker  
      networks:
        - app-net
  
  volumes:
    couchdb-data-volume:
  
  networks:
    app-net:
  
  ```
  
  The URL from the *app* to the *couchdb* service would be `http://couchdb:5986`. To test this, open bash inside the *app* service with `docker exec -it app`. This depends on the *container\_name* setting.
  
  
  ---
  
  