-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdocker_deploy.sh
More file actions
executable file
·36 lines (29 loc) · 883 Bytes
/
docker_deploy.sh
File metadata and controls
executable file
·36 lines (29 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
CONTAINER_NAME="telegrambot-openai-api"
IMAGE_NAME="telegrambot-openai-api"
# Function to stop and remove existing container
cleanup() {
echo "Stopping container if it's running..."
sudo docker stop ${CONTAINER_NAME} || true
echo "Removing container if it exists..."
sudo docker rm ${CONTAINER_NAME} || true
}
# Function to build and run the container
deploy() {
echo "Building Docker image..."
sudo docker build --no-cache -t ${IMAGE_NAME} .
if [[ $? -ne 0 ]]; then
echo "Error: Docker image build failed."
exit 1
fi
echo "Running Docker container..."
sudo docker run --env-file .env --name ${CONTAINER_NAME} -d ${IMAGE_NAME}
if [[ $? -ne 0 ]]; then
echo "Error: Failed to run the Docker container."
exit 1
fi
echo "Deployment complete."
}
# Execute the functions
cleanup
deploy