import os import subprocess def run_command(command): process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) output, error = process.communicate() if error: print(f"Error: {error}") return output def install_sudo(): run_command("apt-get update") run_command("apt-get -y full-upgrade") run_command("apt-get install -y sudo") def install_docker(): try: subprocess.run(['docker', '--version'], check=True) print("Docker is already installed.") except subprocess.CalledProcessError: print("Docker is not installed. Proceeding with installation...") subprocess.run(['curl', '-fsSL', 'https://get.docker.com', '-o', 'get-docker.sh']) subprocess.run(['sudo', 'sh', 'get-docker.sh']) subprocess.run(['sudo', 'usermod', '-aG', 'docker', '$USER']) print("Docker installation complete.") def main(): run_command("docker build -t my-docker-image .") run_command("docker run my-docker-image") if __name__ == "__main__": install_sudo() install_docker() main()