Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.9 kB
1
Indexable
Never
import docker

# Connect to the Docker daemon
client = docker.from_env()

# Define a network name
network_name = "my_network"

# Create a network
try:
    network = client.networks.create(network_name, driver="bridge")
    print(f"Network {network_name} created successfully.")
except docker.errors.APIError as e:
    print(f"Error creating network: {e}")
    exit(1)

# Define image names with versions
ache_image = "vidanyu/ache"
elasticsearch_image = "docker.elastic.co/elasticsearch/elasticsearch:8.9.0"
torproxy_image = "dperson/torproxy"

# Container names
ache_container_name = "ache_container"
elasticsearch_container_name = "elasticsearch_container"
torproxy_container_name = "torproxy_container"

# Start Elasticsearch container
try:
    elasticsearch_container = client.containers.run(
        image=elasticsearch_image,
        name=elasticsearch_container_name,
        environment=[
            "discovery.type=single-node",
            "cluster.name=docker-cluster",
            "bootstrap.memory_lock=true",
            "xpack.security.enabled=false",
        ],
        ulimits={"memlock": {"soft": -1, "hard": -1}},
        volumes={"elastic_volume": {"bind": "/usr/share/elasticsearch/data", "mode": "rw"}},
        ports={"9200/tcp": 9200},
        network=network_name,
        detach=True,
    )
    print(f"Elasticsearch Container {elasticsearch_container_name} started successfully.")
except docker.errors.APIError as e:
    print(f"Error starting Elasticsearch container: {e}")

# Start Torproxy container
try:
    torproxy_container = client.containers.run(
        image=torproxy_image,
        name=torproxy_container_name,
        ports={"8118/tcp": 8118},
        network=network_name,
        detach=True,
    )
    print(f"Torproxy Container {torproxy_container_name} started successfully.")
except docker.errors.APIError as e:
    print(f"Error starting Torproxy container: {e}")

# Start ACHE container
try:
    ache_container = client.containers.run(
        image=ache_image,
        name=ache_container_name,
        command="startCrawl -c /config/ -s /config/tor.seeds -o /data -e tor",
        ports={"8080/tcp": 8080},
        volumes={"./data-ache/": {"bind": "/data", "mode": "rw"}, "./": {"bind": "/config", "mode": "rw"}},
        network=network_name,
        links=[(torproxy_container_name, "torproxy"), (elasticsearch_container_name, "elasticsearch")],
        depends_on=[torproxy_container_name, elasticsearch_container_name],
        detach=True,
    )
    print(f"ACHE Container {ache_container_name} started successfully.")
except docker.errors.APIError as e:
    print(f"Error starting ACHE container: {e}")

# Cleanup: Remove the network (optional)
try:
    network.remove()
except docker.errors.APIError as e:
    print(f"Error removing network: {e}")
Leave a Comment