-1

Could anyone pls bring some clarification on this:
I have this yaml with several services

version: "3.3"
services:
  db:
    image: postgres:11.6
    restart: always
    environment:
      ENV1: VAL1
      ENV2: VAL2

I need somehow to get the container name to create and retrieve a db_dump file from there. I can't use docker ps cause this happens in a github action. I have this string to do it:

docker exec -d $CONTAINER_ID pg_dump -f $db_dump_file $db_mame && docker cp $CONTAINER_ID:[src_file] [dest_file]  

Any suggestions on how to get the $CONTAINER_ID are appreciated.
Thank you in advance

servusMori
  • 9
  • 1
  • 4
  • There's a `docker-compose exec` that knows how to map the container names; or you could use `docker ps` to find it; but if you're able to publish `ports:` out of your container, running `pg_dump` directly from the host is probably easiest (you will need the PostgreSQL tools but not any of the other setup). – David Maze Sep 24 '22 at 11:05

1 Answers1

0
version: "3.3"
services:
  db:
    image: postgres:11.6
    container_name: my_container

This will set a name for your container.

Mihai
  • 9,526
  • 2
  • 18
  • 40