Running a docker container in a docker network which is already created by a docker-compose

  docker, docker-compose, docker-networking

For implementing integration tests for a project that I’m working on, there’s a requirement to run integration tests by spinning up services as docker containers. So there are 2 services that stay in a fixed state through out the tests and those services are added into a docker-compose file. I am starting those services at the beginning of the tests. After that for a group of tests, I need to start another service using docker run command and add that service into the same network that is created when I start the previous 2 services as docker-compose. Is that possible ?

I tried the following steps to ensure that adding a docker container to a network created by docker-compose is possible or not.

  1. Sample docker-compose file.
version: '3.7'
    image: solsson/http-echo
      - envoymesh
      - PORT=8000 

    name: envoymesh
    driver: bridge

  1. Run another docker container and try to add to the same network.
docker run solsson/http-echo -e PORT=9000 --network=envoymesh --driver=bridge
  1. Run docker network inspect envoymesh to see the containers in the network. But I’m seeing only the container from the docker-compose.
 "Containers": {
            "bd3c1b20be141cc66144f24a7e7adeaaa894e694004139f88f2b9563c729e8e1": {
                "Name": "docker-network_backend_service_1_1",
                "EndpointID": "d43f97ef5f0948ed2f6c7e4045164439ebf2596176868efcf6640927c1bc376e",
                "MacAddress": "02:42:ac:1b:00:02",
                "IPv4Address": "",
                "IPv6Address": ""

What am I doing wrong here ? Is it possible to achieve my requirement ?? Thanks in advance.

PS: docker network connect envoymesh [container id] works.

Source: Docker Questions