How to check whether a docker service is already running on UCP using shell script

  • I want to check whether a docker service is running or not.
    • if it’s running I want to remove that service and create the new one
    • I am doing this task with shell script

I am providing the code snippet of my shell script where I am facing
Error response from daemon: service data-mapper-service not found

if [[ "$(docker service inspect ${DOCKER_SERVICE_NAME}  2> /dev/null)" != "" ]]; then
  docker service rm ${DOCKER_SERVICE_NAME}
else echo "service doesn't exist or may have been removed manually"
fi
docker service create \
    --name ${DOCKER_SERVICE_NAME} \
    --network ${OVERLAY_NETWORK} \
    --reserve-memory ${10} \
    --constraint node.labels.run_images==yes \
    --mode global \
    --with-registry-auth \
    --restart-condition any \
    -p ${EXTERNAL_PORT}:${INTERNAL_PORT} \
    -e "SPRING_PROFILES_ACTIVE="${SPRING_PROFILE} \
    -e "JAVA_OPTS: -Xms256m -Xmx512m" \
    ${DTR_HOST_NAME}/${DTR_ORG_NAME}/${DTR_REP_NAME}:${BUILD_NUMBER}

I am getting the error on if statement line.

  • How to recover from
  • Linked docker containers can't communicate with each other
  • Docker: how do I make a DNS entry for a not yet started container available in another container
  • Dockerize Multi Module Maven Project
  • Installing openjdk-7-jre blocked when “setting up ca-certificates-java” on Debian
  • How to tell docker worker node belong to which swarm?
  • If the service is running and I trigger this shell script everything runs fine, But if the service is not running and I trigger this shell script I am facing above mention error.

  • How do I populate a volume in a docker-compose.yaml
  • How can I disable the default composer install in CircleCI?
  • Docker, nginx and several sites on one server
  • knife container workflow clarification
  • Bind Docker to a Unix socket under upstart in kubernetes master node
  • Getting console output from Docker container
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.