Skip to content

Allow supplying container name when creating a container with docker executor run #853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vnghia opened this issue Feb 20, 2025 · 4 comments

Comments

@vnghia
Copy link
Contributor

vnghia commented Feb 20, 2025

Hello. This functions also take a name for the newly created container. Could you add an option to supply that option ?

ctx, &containerConfig, e.hostConfig, e.networkConfig, nil, "",

Thank you very much for this project :D

@vnghia
Copy link
Contributor Author

vnghia commented Feb 20, 2025

I am thinking that we could reuse the containerName field with the rule that if image is not specified or exec is not null, we fall back to exec and if the image is not null, we will pass it to that function. What do you think @yohamta ? I can send a PR for that

@yottahmd
Copy link
Collaborator

@vnghia Sounds like a great idea! Yes, please!

@Lewiscowles1986
Copy link
Contributor

@vnghia would stopping the containers then become a responsibility of the workflow orchestrator, rather than step? I'd have thought docker steps would stop containers once the step is complete. Always curious to learn more.

@vnghia
Copy link
Contributor Author

vnghia commented Feb 21, 2025

My main use case for dagu is spawning ephemeral containers. I have a lot of dags which shares the same executor configuration and has only one step for a single, well-define intention. You can imagine something like this.

steps:
- command: backup
  executor:
    config:
      autoRemove: true
      container:
        env:
        - RESTIC_CACHE_DIR=/cache
        - RESTIC_REPOSITORY=${RESTIC_REPOSITORY}
        - RESTIC_PASSWORD=${RESTIC_PASSWORD}
      host:
        binds:
        - restic-cache:/cache:rw
        - backup-volume-1:/volume-1:rw
        - backup-volume-2:/volume-2:rw
      image: restic
    type: docker
  name: backup

This works great and the fact that we can write down a container configuration for later execution (just like docker compose) is a dream for someone obsessed with Infra-as-code like me (yes, my dags were generated and managed by pulumi :D).

Sometime, I need to run some less common commands or to debug my executor, so I have this dag.

steps:
- command: sleep 30m
  executor:
    config:
      autoRemove: true
      container:
        entrypoint: []
        env:
        - RESTIC_CACHE_DIR=/cache
        - RESTIC_REPOSITORY=${RESTIC_REPOSITORY}
        - RESTIC_PASSWORD=${RESTIC_PASSWORD}
      host:
        binds:
        - restic-cache:/cache:rw
        - backup-volume-1:/volume-1:rw
        - backup-volume-2:/volume-2:rw
      image: restic
    type: docker
  name: hang

And then I can just docker exec -it <newly-created-container-id> /bin/bash to do whatever I want. This is the reason why I want to supply a container name so I can access to the container by name rather by id which will change everytime the container is created.

For your question, I still think that stopping the containers should be the responsibility of a step. Because we can not reuse the docker executor:

  • Newly-created container will run only the command they are assigned to (you can not change command once the container is created).
  • Execing to a container only takes one command to run (unless you run /bin/bash but it counted as one executable unit too).

Furthermore, the main philosophy of docker is somewhat running only one process per container which can count as one step in Dagu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants