I am trying to have my own network name on debian:jessie for my docker-compose files (server.yml and test.yml), as test.yml gets only started from time to time, but needs access to some services in the server.yml. I can make it work with docker-compose -p nameofproject up, but not with COMPOSE_PROJECT_NAME.
serverstack_mynetwork
just like when I do the following, which actually works
docker-compose -p serverstack up
And then I can connect just by using docker-compose up with the second file (which works just fine when using the -p option on the server.yml)
As far as I know, you cannot set the project name directly inside the compose file (see Proposal: make project-name persistent. · Issue #745 · docker/compose · GitHub)
You have to use the -p flag or set the COMPOSE_PROJECT_NAME environment variable before running docker-compose either by exporting the variable or by setting it in a .env file.
Strange that the doc would then mention file names…???
Is the COMPOSE_PROJECT_NAME=serverstack in an .env treated as a system variable? In other words, if I have two different .env files, in different folders, for 2 different projects and each defines the variable, does the call of the 2nd project also override the 1st?
env_file provides environment variables to a container, but are not available to the Compose file. That’s why ${COMPOSE_PROJECT_NAME}-mynetwork won’t work while using env_file directive.
On the contrary, .env provides environment variables for use inside the Compose file.
so what you are saying ist that for COMPOSE_PROJECT_NAME I need to use .env file, so that the Compose file sees it, but I do not need to declare env_file: .env in the docker-compose.yml (tested and confirmed). That also seems to suggest that I can still use asecond.env with other variables and a name (this is just not seen by the Compose file)
It starts to make sense. So I changed to not have env_file: .env (I was wondering why making it redundant, if it can be only named .env )
But when I start the test.yml (with serverstack_mynetwork) I see the following
Found orphan containers (serverstack_app1_1, serverstack_app2_1) for this project. What does that mean?