0

I have dev-docker-compose.yml with several backends and several databases like postgres, redis etc... Now I want to create test-docker-compose.yml with changed name for the services For example I had:

  postgres:
    image: postgres
    restart: always
    ports:
    - "5432:5432"
    volumes:
      - postgres:/var/lib/postgresql/data

and now i have changed it to

  test_postgres:
    image: postgres
    restart: always
    ports:
    - "5432:5432"
    volumes:
      - test_postgres:/var/lib/postgresql/data

But when I connect to it with navicat or dbeaver I see the same values that was in first variant.

Can somebody explain me why this behavior exist and how to solve it?

Wie
  • 422
  • 4
  • 20
illdo
  • 41
  • 1
  • 7
  • Did you run `docker-compose down` bevor? – Wie Jun 04 '19 at 14:29
  • Have you tried using a different volume path for the test DB? – Yaron Idan Jun 04 '19 at 14:34
  • @YaronIdan can you provide which path, depending on what i provide, ? – illdo Jun 04 '19 at 15:27
  • @Wie if i do docker-compose down - will i lose all the data from databases? – illdo Jun 04 '19 at 15:28
  • @illdo Just try changing the last line in your docker-compose.yaml from `- test_postgres:/var/lib/postgresql/data` to `- test_postgres:/var/lib/test_postgresql/data` – Yaron Idan Jun 04 '19 at 17:41
  • @Yaron Idan Dear, are you sure? because `/var/lib/postgresql/data` its required by postgresql container setup, its defaul location of postgresql data. When i do new container- anyway that value should be another ( in new container)- new volume – illdo Jun 04 '19 at 19:21
  • I see what you're saying but I just think you should rule out the possibility that docker is reusing the volume between both containers. – Yaron Idan Jun 05 '19 at 02:35
  • Have you check docker service and container of service, is it running ur new `test-docker-compose.yml` ? Did you `docker-compose down` for your old service and `docker-compose up` for you new service? – Vengleab SO Jun 05 '19 at 02:37
  • @vengleabso , dude ii do `down ` i ll lose data - i can not do down. because i need the data. Please understand it – illdo Jun 05 '19 at 08:26
  • `down` does not remove volumes, unless you explicitly specify the `-v` flag, so your data should be fine. However - if the data you have on the volume is important, saving it in an anonymous volume seems very risky anyway. – Yaron Idan Jun 05 '19 at 11:06
  • 1
    @YaronIdan is right, you should not loose data. And your volumes are named. If you do only `docker-compose up` your service will refresh with the same properties. Did you run `docker-compose -f path/to/your/file.yaml up`? – Wie Jun 05 '19 at 11:50

0 Answers0