Skip to content

Running Docker Container with Python Script

Sayali Oak edited this page Jul 30, 2024 · 1 revision

This document provides instructions for creating and running a Docker container using a Python script. The script pulls a Docker image from Docker Hub, removes any existing container with the same name, and starts a new container. The instructions are applicable for both Windows and MacOS users.

Requirements

  1. Docker installed and running on your system (Windows or MacOS).
  2. Python installed on your system.
  3. Python Script

The Python script link is provided above. It automates the process of pulling a Docker image, removing any existing container, and running a new container. It also provides an option to include SQL scripts for database initialization.

NOTE: If you have SQL scripts for database initialization (adding dummy data), set the 'SQL_SCRIPTS_DIR' and 'CONTAINER_SCRIPTS_DIR' variables, and uncomment the respective lines in the script.

Running the Script

  1. Save the Python script to a file, e.g., 'run_docker_container.py'.
  2. Open a terminal or command prompt and navigate to the directory containing the script.
  3. Run the script using the command: python run_docker_container.py

NOTE: The error message "No such container" is expected when the script tries to remove a container that doesn't exist. This message is not an error in the script's logic; it's simply Docker's way of informing you that there was no existing container to remove.

Clone this wiki locally