Newbie Question - How to run multiple containers running the same services without them stopping each other

Hi all, I’m still relatively new to using docker as I didn’t really have a need for it up until a 6 months ago but I’ve been struggling with something simple that I thought was working but turns out that it is not and I’ve been unable to find any actual documentation or comments with the same issue I am facing.

I often work on multiple projects at the same time where each project may require the same services (E.G MySQL, Elastic, Neo4j, Memcached, Redis, MariaDB). The trouble I am facing is I do not know how I can run multiple containers at the same time without that stopping each other.
What I’m trying to achieve is the ability to run unit tests on some projects at the same time whilst working on a third project.

I am using docker-compose, with up -d and YML files to launch the services. Each YML file works to launch the serices and I can see them running find using sudo docker ps but as soon as I try to bring up a second project, if the service clashes then it “recreates” the container, stopping the previous one and launching a new one with the new name.

Each of my YML files use different port mapping to avoid clashes as well as using container_name which I thought was the correct way of doing this so that each service would launch within its own container.

Here is an example of one of the YML files for a project using memcached and MariaDB

version: '3'
    image: memcached
    container_name: proj1-memcached
      - "51211:11211"
    image: mariadb:latest
      MYSQL_ROOT_PASSWORD: my-root-passowrd
      MYSQL_DATABASE: databasea
      MYSQL_USER: some-user
      MYSQL_PASSWORD: some-users-passqord
    container_name: proj1-maria
      - '5306:3306'
     - mariadb_pro1:/var/lib/mysql


I would then have a second YML file where the ports would be different, the container names would be different and the volumes would also be different. However after running the second docker-compose the services that clash, say both used MariaDB, would have the container stopped from the first and then launched again in the second.

sudo docker-compose project1.yml up -d
sudo docker ps
sudo docker-compose project2.yml up -d
sudo docker ps

I thought that this was one of the main benefits of using dockers, to run isolated containers where as long as you mapped the ports to different ports and set different container names, you could run the same service multiple times on the same bare metal machine.