简体   繁体   中英

containers not communicating in network in docker-compose

I have a docker-compose networking issue. So i create my shared space with containers for ubuntu , tensorflow , and Rstudio , which do an excellent job in sharing the volume between them and the host, but when it comes down to using the resources of the one container inside the terminal of each other one, I hit a wall. I can't do as little as calling python in the terminal of the container that doesn't have it. My docker-compose.yaml :

# docker-compose.yml

version: '3'
services:

#ubuntu(16.04)
 ubuntu:
   image: ubuntu_base
   build:
     context: .
     dockerfile: dockerfileBase 
   volumes:
     - "/data/data_vol/:/data/data_vol/:Z"
   networks:
     - default
   ports:
     - "8081:8081"
   tty: true

#tensorflow
 tensorflow:
   image: tensorflow_jupyter
   build:
     context: .
     dockerfile: dockerfileTensorflow
   volumes:
     - "/data/data_vol/:/data/data_vol/:Z"
     - .:/notebooks
   networks:
     - default
   ports:
     - "8888:8888"
   tty: true

#rstudio
 rstudio:
   image: rstudio1
   build:
     context: .
     dockerfile: dockerfileRstudio1
   volumes:
     - "/data/data_vol/:/data/data_vol/:Z"
   networks:
     - default
   environment:
     - PASSWORD=test
   ports:
     - "8787:8787"
   tty: true


volumes:
  ubuntu:
  tensorflow:
  rstudio:

networks:
  default: 
    driver: bridge

I am quite a docker novice, so I'm not sure about my network settings. That being said the docker inspect composetest_default (the default network created for the compose) shows the containers are connected to the network. It is my understanding that in this kind of situation I should be able to freely call one service in each one of the other containers and vice-versa:

"Containers": {
            "83065ec7c84de22a1f91242b42d41b293e622528d4ef6819132325fde1d37164": {
                "Name": "composetest_ubuntu_1",
                "EndpointID": "0dbf6b889eb9f818cfafbe6523f020c862b2040b0162ffbcaebfbdc9395d1aa2",
                "MacAddress": "02:42:c0:a8:40:04",
                "IPv4Address": "192.168.64.4/20",
                "IPv6Address": ""
            },
            "8a2e44a6d39abd246097cb9e5792a45ca25feee16c7c2e6a64fb1cee436631ff": {
                "Name": "composetest_rstudio_1",
                "EndpointID": "d7104ac8aaa089d4b679cc2a699ed7ab3592f4f549041fd35e5d2efe0a5d256a",
                "MacAddress": "02:42:c0:a8:40:03",
                "IPv4Address": "192.168.64.3/20",
                "IPv6Address": ""
            },
            "ea51749aedb1ec28f5ba56139c5e948af90213d914630780a3a2d2ed8ec9c732": {
                "Name": "composetest_tensorflow_1",
                "EndpointID": "248e7b2f163cff2c1388c1c69196bea93369434d91cdedd67933c970ff160022",
                "MacAddress": "02:42:c0:a8:40:02",
                "IPv4Address": "192.168.64.2/20",
                "IPv6Address": ""
            }

A pre-history - I had tried with links: inside the docker-compose but decided to change to networks: on account of some warnings of deprecation. Was this the right way to go about it?

Docker version 18.09.1

Docker-compose version 1.17.1

but when it comes down to using the resources of the one container inside the terminal of each other one, I hit a wall. I can't do as little as calling python in the terminal of the container that doesn't have it.

You cannot use linux programs the are in the bin path of a container from another container, but you can use any service that is designed to communicate over a network from any container in your docker compose file.

Bin path:

$ echo $PATH                                                                                                                                                                                              127 ↵
/home/exadra37/bin:/home/exadra37/bin:/home/exadra37/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

So the programs in this paths that are not designed to communicate over a network are not usable from other containers and need to be installed in each container you need them,like python .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM