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.

  • Docker compose wait for without sleep command
  • How do I create a local kubernates cluster in a VM?
  • Docker Build: Missing Dependency
  • Execute chmod in Dockerfile on Raspberry pi /dev/spi*
  • Why I can't find ip_vs module or use ipvsadm when I add privileged
  • Unable to finding the option to set docker workspace option when running the docker image
  • 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.

  • Are etcdctl client connections to etcd atomic?
  • Running multiple docker instances in EC2
  • docker-compose gives error “ImportError: No module named ssl_match_hostname” when run as normal user
  • How can ichange a virtualbox configuration using docker-machine
  • Cannot see Ipython notebook interface on a browser using Docker Kitematic
  • What is the best way to run an Ubuntu server on Windows with Docker and develop with an IDE?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.