Running a script after docker creation


neruve

Recommended Posts

I don't know if this is possible or not. I'm not super familiar and still learning. Is there a way to run a script after creating and starting the container for the first time? My current use case is that I have an MSSQL container and I want to enable SSIS but its a seperate install. So I would like to create a script with the commands to install SSIS everytime the container is created (or updated) but it needs to only run one time on the initial startup of the container. 

 

Anyone have any suggestions?

Link to comment

Okay, so i'm trying to run these commands inside my sqlserver docker.

 

https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-ssis?view=sql-server-ver15

 

However, I can't do anything, sudo doesn't exists, curl doesn't exist and when i try to install curl i get the following:

 

$ apt-get install curl
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

 

i'm a complete n00b here as far as things inside a container. Can anyone provide any insight?

Link to comment
10 minutes ago, knex666 said:

I would use a base Image and create my own. YOu can create a docker file or you can exec it into the Container install everything and after you finished you make a commit to your own Image. 

 

This is a little above my head. Any other info you can provide or links on where to start?

Link to comment
  • 1 year later...

I know this topic is old... but when investigating this, I found the solution for this IF you are using a Linuxserver docker. @Roxedus pointed to the solution above; BUT it was not quite working.

 

In my case, I was trying to run a script to the SWAG docker.

 

In /cache/appdata/swag folder, create a folder called "custom-cont-init.d"

 

in that folder, create a script file, in my case, I called it install.sh.

 

Here are the contents of this file:

#!/bin/bash
echo "**** Sending Update/Upgrade Commands ****"
apk ugrade
apk update
echo "**** installing OpenSSH and MC ****"
apk --update add --no-cache  openssh
apk --update add --no-cache  mc

 

For installing packages to your Docker, the upgrade and update commands are critical. Otherwise you will get a "package not found" error.

 

Re-install the Docker, and the script gets executed. Check out the Dockers log page and you will see the results of the script.

 

Amazing thing about the LSIO guys, they think of EVERYTHING.... Donate!

 

 

 

Edited by hernandito
Link to comment

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.