You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.2 KiB

  1. #!/bin/bash
  2. if [[ $1 == "help" ]]; then
  3. echo "lc (Launch Container) help:
  4. ===========================
  5. - lc new <dockerfile> <container_name> <image_name>: create new image &
  6. container using the selected dockerfile
  7. - available dockerfiles: go, rust
  8. - lc stop <container_name>: stop container
  9. - lc rm <container_name>: remove container
  10. - lc ls: list containers
  11. - lc stop <container_name> <image_name>: stop container
  12. - lc <container_name>: launch container
  13. "
  14. exit 0
  15. elif [[ $1 == "new" ]]; then
  16. # $2: lang, $3: container_name, $4: image_name
  17. lang=$2
  18. if [[ $lang == "rust" ]]; then
  19. lang="Dockerfile.rust"
  20. elif [[ $lang == "go" ]]; then
  21. lang="Dockerfile.go"
  22. else
  23. echo "available dockerfiles: go, rust"
  24. exit 0
  25. fi
  26. sudo docker build -t $4 -f $lang .
  27. sudo docker run -it --entrypoint=/bin/bash --name $3 $4
  28. exit 0
  29. elif [[ $1 == "stop" ]]; then
  30. # $2: container_name
  31. sudo docker stop $2
  32. exit 0
  33. elif [[ $1 == "rm" ]]; then
  34. # $2: container_name
  35. sudo docker stop $2
  36. sudo docker rm $2
  37. exit 0
  38. elif [[ $1 == "ls" ]]; then
  39. sudo docker ps -a
  40. exit 0
  41. fi
  42. # $1: container_name, $2: image_name
  43. sudo docker start $1
  44. sudo docker container exec -it $1 bash