djt
djt

Reputation: 7535

Running multiple Docker containers on OSX in separate codebases

I have a Laravel project and I made a Docker environment (using Docker Compose) which has the following:

They're all linked on a network called my-net

Now, I also have a separate github repo called admin, which is an admin panel in ReactJS. The ReactJS project uses the Laravel project as a backend (uses routes in the admin namespace)

So in this project, I want to setup a Dockerfile as well, but I want it to have access to the Laravel project's network (my-net). How is this achieved? Obviously, it seems that the admin project's Dockerfile cannot refer to my-net, because it doesn't know it exists. Should I just be routing requests via the "public" and hit localhost:80/admin/x/y/z? Or is there an internal-network way of achieving this?

Upvotes: 0

Views: 451

Answers (1)

whites11
whites11

Reputation: 13270

You cannot hit localhost because it is simply wrong (localhost for a docker container is not your host's address, but container's address).

That said, you can use a network created with compose with a standard docker container. What you are missing is that the network is not called my-net as you expect but something like <folder name>-my-net where <folder name> is the folder where your docker-compose.yml file is located.

To find the correct name of the network to be used you can run docker network ls.

As an alternative, you could create a network manually with docker network create mynet and declare it as external in the docker-compose.yml file:

services:
  srvc:
    ...
    networks:
    - mynet
  ...
networks:
  mynet:
    external:
      name: mynet

Upvotes: 1

Related Questions