Start the pod with a custom command after the pod finishes startup

How can add I command that the pod will execute after it has finished starting up? I tried using
bash -c 'apt update;DEBIAN_FRONTEND=noninteractive apt-get install openssh-server -y;mkdir -p ~/.ssh;cd $_;chmod 700 ~/.ssh;echo "$PUBLIC_KEY" >> authorized_keys;chmod 700 authorized_keys;service ssh start;sleep infinity'
bash -c 'apt update;DEBIAN_FRONTEND=noninteractive apt-get install openssh-server -y;mkdir -p ~/.ssh;cd $_;chmod 700 ~/.ssh;echo "$PUBLIC_KEY" >> authorized_keys;chmod 700 authorized_keys;service ssh start;sleep infinity'
And replaced sleep infinity with apt install nano -y
bash -c 'apt update;DEBIAN_FRONTEND=noninteractive apt-get install openssh-server -y;mkdir -p ~/.ssh;cd $_;chmod 700 ~/.ssh;echo "$PUBLIC_KEY" >> authorized_keys;chmod 700 authorized_keys;service ssh start;apt install nano -y'
bash -c 'apt update;DEBIAN_FRONTEND=noninteractive apt-get install openssh-server -y;mkdir -p ~/.ssh;cd $_;chmod 700 ~/.ssh;echo "$PUBLIC_KEY" >> authorized_keys;chmod 700 authorized_keys;service ssh start;apt install nano -y'
The container starts but I am unable to access it using ssh or the web terminal.
Solution:
You can try the other way around:
apt update && apt -y install nano && /start.sh
apt update && apt -y install nano && /start.sh
...
Jump to solution
21 Replies
Asad Cognify
Asad CognifyOP6mo ago
No description
Asad Cognify
Asad CognifyOP6mo ago
That is all the info it gives and doesnot start the terminal
Madiator2011
Madiator20116mo ago
you overwritten docker image start command so it's only executing what you do and then wait with bash
Asad Cognify
Asad CognifyOP6mo ago
I found this here. How do add commands to execute after the pod has sucessfully started?
No description
Asad Cognify
Asad CognifyOP6mo ago
I am using the pytorch template
Madiator2011
Madiator20116mo ago
you would need to run start script btw you do not need to do it for PyTorch template as it's already have ssh setup
Asad Cognify
Asad CognifyOP6mo ago
What is the start script or how can I run it? Yes, but I want to run a few scripts as the pod starts rather than running them manually each time
nerdylive
nerdylive6mo ago
From the template
Asad Cognify
Asad CognifyOP6mo ago
How?
nerdylive
nerdylive6mo ago
Hmm find the template and edit the file
Asad Cognify
Asad CognifyOP6mo ago
Okay so where to find the template? On docker hub? And I saw a start.sh script on the root of the container which I think is think is the startup script
Asad Cognify
Asad CognifyOP6mo ago
No description
No description
Asad Cognify
Asad CognifyOP6mo ago
So how can I add some scripts to run after start.sh?
Asad Cognify
Asad CognifyOP6mo ago
Would this work?
No description
digigoblin
digigoblin6mo ago
No, because start.sh has sleep infinity so the commands after it would never be reached
Asad Cognify
Asad CognifyOP6mo ago
can I modify the start.sh? How do I add my commands to run after it has finished executing?
nerdylive
nerdylive6mo ago
Not sure, find it on Google or somewhere What template are you using?
digigoblin
digigoblin6mo ago
Its the pytorch template, its shown in the screenshot
Solution
digigoblin
digigoblin6mo ago
You can try the other way around:
apt update && apt -y install nano && /start.sh
apt update && apt -y install nano && /start.sh
digigoblin
digigoblin6mo ago
but you probably need bash -c
bash -c 'apt update && apt -y install nano && /start.sh'
bash -c 'apt update && apt -y install nano && /start.sh'
Asad Cognify
Asad CognifyOP6mo ago
pytorch 2.2.0
Want results from more Discord servers?
Add your server