Run a script after docker container starts?


stchas

Recommended Posts

I'd like to be able to automatically run a script after a docker container starts. How might I do that?

 

Couple of examples of what I'd like to do:

[*]change the permissions on appdata/crashplan/conf/service.model to 0666 (changed to 0600 in CP rev 4.5, creates SyncBack error)

[*]create a revised appdata/crashplan/id/.ui_info with the unRAID server IP address substituted for 0.0.0.0 (broken in CP circa rev 4.1?)

I don't need help creating the script(s); what I need help on is figuring out how to have the docker manager run the script(s) automatically when the container is started.

 

Thanks in advance for your help!

Link to comment

Change the docker container itself to have that done on startup. Depending on which docker container and which base image they use will determine how to hook into that startup.

 

You could do it on the unraid side, but why not fix what was broken where it was broken to begin with?

 

If you're using a LinuxServer container I'm sure the fine folks there would help you out. I could also see them changing all there containers to support user adjustable startup scripts as a new feature.

Link to comment

You basically put the script in your GitHub repository and then put commands like this at the end of the Dockerfile to install and run it.

 

ADD install.sh /tmp/

RUN chmod +x /tmp/install.sh && /tmp/install.sh && rm /tmp/install.sh

 

The above copies the script install.sh into the docker, runs it and then deletes it.

 

But then, I'm guessing you really want to do it without creating your own repository, right?

Link to comment

... why not fix what was broken where it was broken to begin with?

The two items I'm working on are work-arounds for changes Code42 implemented in recent revisions of CrashPlan.  They have not been particularly responsive to requests for relief. You know the drill: "... running the CrashPlan service on a headless computer is an unsupported feature..." and "... security decision made by our engineers that we have no intention of reversing."

 

If you're using a LinuxServer container ...

No, this is a gfjardim container

 

But then, I'm guessing you really want to do it without creating your own repository, right?

Right; wasn't quite ready to take that step.

 

I was really hoping there was a generic hook in the docker manager that would facilitate user scripts that I didn't know about. I can't believe I'm the only one that might see a use for this feature.

 

Thanks for the ideas, guys!

Link to comment
  • 1 year later...
31 minutes ago, Flick said:

Did you ever find a way to do this? Thanks!

Easiest solution would be to set the docker app to NOT autostart, then create a user script vis a vis user scripts plugin set to run at array start containing something like this:

 

sleep xxx  (xxx is however long it takes for the other containers, VMs, etc to get up and running)

docker start nameOfContainer

whateverOtherCommandsYouWant

 

Edited by Squid
  • Upvote 2
Link to comment
  • 9 months later...
On 14-5-2017 at 8:58 PM, Squid said:

Easiest solution would be to set the docker app to NOT autostart, then create a user script vis a vis user scripts plugin set to run at array start containing something like this:

 

sleep xxx  (xxx is however long it takes for the other containers, VMs, etc to get up and running)

docker start nameOfContainer

whateverOtherCommandsYouWant

 

 

Although this is a cool way to have a post-startup script for the initial container launch, right after the array startup, this would not make the container restartable with the script.

 

For example, I want to run 

docker network connect bridge poste

right after the poste container - which is on a macvlan - starts, to add a second network to the container.

However, I might want to restart / stop-start the container at runtime.

I'd love to have a post-start and post-stop command (to be run on the host) option in the docker GUI.

I can think of a few more examples that cannot be included in the dockerfile.

  • Like 2
Link to comment
  • 5 years later...

I just added in the "Post Arguments" box the following to install ffmpeg into the nextcloud container after it has been started:

 

&& docker exec -u root nextcloud bash -c "apt update && apt install -y ffmpeg"

 

The "&&" causes the docker run command to finish and upon success executes what comes after it as a new command. You can put in whatever you like. Works for me, hopefully it works for others as well. But I agree that maybe another script box would be nicer and cleaner.

Link to comment
  • 5 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.