42 lines
1.1 KiB
Plaintext
Executable File
42 lines
1.1 KiB
Plaintext
Executable File
# --rm: automatically remove the container when it exits
|
|
|
|
# Check if a container name was provided
|
|
if [ $# -eq 0 ]; then
|
|
echo "Usage: $0 <container_name>"
|
|
exit 1
|
|
fi
|
|
|
|
IMAGE="web-stack"
|
|
NAME="${IMAGE}-$1"
|
|
|
|
# Function to exec into the container
|
|
exec_into_container() {
|
|
docker exec --detach-keys "ctrl-q,ctrl-p" -it $NAME /bin/zsh
|
|
}
|
|
|
|
# Check if the container exists
|
|
if [ "$(docker ps -a -q -f name=$NAME)" ]; then
|
|
# Container exists, start it if it's not running
|
|
if [ ! "$(docker ps -q -f name=$NAME)" ]; then
|
|
echo "Container $NAME exists but is not running. Starting it..."
|
|
docker start $NAME
|
|
else
|
|
echo "Container $NAME is already running."
|
|
fi
|
|
else
|
|
echo "Container $NAME does not exist. Creating and running it in detached mode..."
|
|
docker run -d \
|
|
--detach-keys "ctrl-q,ctrl-p" \
|
|
--network host \
|
|
-v $HOME/.ssh:/home/dev/.ssh \
|
|
-v $PWD:/workspace \
|
|
--name $NAME \
|
|
--init \
|
|
$IMAGE \
|
|
tail -f /dev/null
|
|
fi
|
|
|
|
# Exec into the container
|
|
echo "Executing into container $NAME..."
|
|
exec_into_container
|