Skip to content

Instantly share code, notes, and snippets.

@Sharkbyteprojects
Last active October 18, 2022 20:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sharkbyteprojects/c91b9c2919f39a56180e332745f92e89 to your computer and use it in GitHub Desktop.
Save Sharkbyteprojects/c91b9c2919f39a56180e332745f92e89 to your computer and use it in GitHub Desktop.
Python (DockerSDK) SSH Docker Testinstallation
#!/usr/bin/env python
# ©️Sharkbyteprojects
# required packet: docker
def cleanUpDocker(i, cont):
if i == 0 and cont == 0:
return
print("\nWait a Second ...\nI clean up my own junk!")
if cont != 0:
try:
cont.stop()
except:
print(
"Container Stop Fault!\n"
"Maybe it isn't running?"
)
try:
i.remove()
except:
print("Remove the Image by yourself!")
def main():
i = 0
cont = 0
try:
print("Connect to Docker")
client = docker.from_env()
print("Fetch Image")
i = client.images.pull("sharkbyteprojectsadmin/ssh_test_app")
print("SSH username & password: testuser\nLogin: ssh testuser@localhost")
cont = client.containers.run(i, detach = True, ports = {'22/tcp': 22}, remove=True, name="sshServer")
input("Press Enter to Exit...")
cleanUpDocker(i, cont)
except KeyboardInterrupt:
cleanUpDocker(i, cont)
except:
print("Start/Install Docker (Not the SDK) first!")
if __name__ == "__main__":
try:
print(
"<c> Sharkbyteprojects\n"
"Note: If you wan't to clean up Docker things that didn't belong to this App"
" (This app remove the data before closing), you can run \"docker system prune -a\""
"\n")
import docker
main()
except:
print(
"Maybe you need to install the Docker SDK for Python?\n\"pip install docker\"\n"
"Or, if requirements.txt is shipped with this python script, run \"pip install -r requirements.txt\"")
MIT License
Copyright (c) 2022 Sharkbyteprojects
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment