Answer the question
In order to leave comments, you need to log in
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 run
non-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
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
myapp_default
. php-fpm
it is necessary to be connected somehow to a DB. How? php-fpm
specify additional for the service. network
, where prescribed name: default
, but it did not work. Yes, and by name you can not find default
a 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
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 mysql
as required.
network_mode: bridge
in the description of the services will shove them into the default Docker network, paired with this parameter must be filled links
in due to the nature of this network.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question