I have two projects and I need two differents docker environnement (containers). I have two docker-compose.yml
files in two different projects. foo
project and bar
project.
foo/src/website/docker-compose.yml
#1 (foo
)
version: '3'
services:
db:
env_file: .env
image: mariadb:10.0.23
container_name: foo-db
ports:
- "42333:3306"
restart: always
web:
image: project/foo
container_name: foo-web
env_file: .env
build: .
restart: always
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails server -p 3000 -b '0.0.0.0'"
volumes:
- .:/webapps/foo
ports:
- "3000:3000"
depends_on:
- db
bar/src/website/docker-compose.yml
#2 (bar
)
version: '3'
services:
db:
image: mysql:5.5.50
container_name: bar-db
ports:
- "42333:3306"
env_file: .env
restart: always
web:
image: project/bar
container_name: bar-web
env_file: .env
build: .
restart: always
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails server -p 3000 -b '0.0.0.0'"
volumes:
- .:/webapps/bar
ports:
- "3000:3000"
depends_on:
- db
I do this command for my foo
project docker-compose build
and docker-compose up
, everything works. In Kitematic I see my two containers with the good names (foo-web
).
docker-compose stop
. bar
) and run docker-compose build
and docker-compose up
. everything works, but my container name in now replaced by bar-web
. docker-compose stop
and I try to perform docker-compose up
in my foo
project folder again but it fails.How can I keep two different containers and easily switch from one to the other with docker-compose stop
and docker-compose up
?
I found the issue, the main folder where my docker-compose.yml
are located for my two projects have the same folder name. Can I fix this or I need to rename my folders?
The docker-compose. yml file allows you to configure and document all your application's service dependencies (other services, cache, databases, queues, etc.). Using the docker-compose CLI command, you can create and start one or more containers for each dependency with a single command (docker-compose up).
Kill All Containers Using Docker Compose If you do, killing multiple containers takes one command: docker-compose down. You could also run docker-compose without detached mode. If so, you'll just use ^C to kill all containers. And there you have it—all containers killed!
You can restart automatically an unhealthy container by setting a smart HEALTHCHECK and a proper restart policy. The Docker restart policy should be one of always or unless-stopped . The HEALTHCHECK instead should implement a logic that kills the container when it's unhealthy.
Yes, the directory name is the default project name for docker-compose
:
$ docker-compose --help
...
-p, --project-name NAME Specify an alternate project name (default: directory name)
Use the -p
argument to specify a particular non-default project name.
Alternatively, you can also set the COMPOSE_PROJECT_NAME
environment variable (which defaults to the basename
of the project directory).
If you are sharing compose configurations between files and projects with multiple compose files, refer to this link for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With