S
S
Sergey Sokolov2019-11-18 17:02:30
Docker
Sergey Sokolov, 2019-11-18 17:02:30

How to connect to a running container on the default network from a docker compose application?

The host is running MySQL in a container running over a docker runnon-default network.
There is also a version of the application in development, which raises its services through docker-compose up.
The application will have its own MYSQL, but during development it would be nice to connect with an already running MySQL.
Is it possible and how?
Sample command to start MySQL:

docker run		\
        --name mysql	\
        -p 3306:3306	\
        -d				\
        mariadb

myapp/docker-compose.yml :
version: '3'
services:
  redis:
    container_name: composed_redis
    image: redis:latest

  php-fpm:
    container_name: composed_php_fpm
    image: my/php-fpm

  nginx:
    container_name: composed_nginx
    image: nginx:alpine
    ports:
      - "100500:80"
    depends_on:
      - php-fpm

This creates a network myapp_default.
From service php-fpmit is necessary to be connected somehow to a DB. How?
I tried to php-fpmspecify additional for the service. network, where prescribed name: default, but it did not work. Yes, and by name you can not find defaulta service on the network. Only if the custom network was for simple-containers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2019-11-18
@sergiks

I decided on a crutch (?) -  network connect connected the required stand-alone container to the docker-composer's network:
At the same time, the application was already running and the mysql container was running.
After that, the service became available internally under the hostname mysqlas required.

C
chupasaurus, 2019-11-18
@chupasaurus

network_mode: bridgein the description of the services will shove them into the default Docker network, paired with this parameter must be filled linksin due to the nature of this network.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question