Retrieve a db_dump from a docker container

Viewed 15

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

1 Answers
version: "3.3"
services:
  db:
    image: postgres:11.6
    container_name: my_container

This will set a name for your container.

Related