Cannot link to a running container started by docker-compose

后端 未结 3 743
刺人心
刺人心 2020-12-22 21:33

I am setting up my local development environment with docker containers. The docker-compose.yml is like following

version: \'2\'

services:
  db:
    image:         


        
3条回答
  •  借酒劲吻你
    2020-12-22 22:00

    Ok, found the answer to it. In case anyone else comes across the same problem, just do

    docker network ls
    

    This command lists all the docker networks. docker-compose will create a new network when you run docker-compose up. In my case, the network is named as myapp_default.

    Note: Your app’s network is given a name based on the “project name”, which is based on the name of the directory it lives in. You can override the project name with either the --project-name flag or the COMPOSE_PROJECT_NAME environment variable. Networking in Compose

    So the correct way to link to those containers is

    docker run --link my_app_mq_1:mq --link my_app_db_1:db -it --net myapp_default worker 
    

提交回复
热议问题