I
I
Igor2021-02-09 11:53:10
bash
Igor, 2021-02-09 11:53:10

How to stop a non-existent container?

deploy:
  stage: deploy
  image: docker:latest
  variables:
    DOCKER_HOST: tcp://84.202.160.922:2376
  before_script:
    - docker login -u $GITLAB_USER_LOGIN -p $REGISTRY_TOKEN $CI_REGISTRY
  script:
    - docker stop $CI_PROJECT_NAME
    - docker run -p 3000:80 --rm -d --name $CI_PROJECT_NAME $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:app.$CI_PIPELINE_ID
  only:
    - develop


Pay attention to docker stop $CI_PROJECT_NAME
Docker will crash if there is no such container, this is quite fair.

Is there a way to check if a container exists?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-02-09
@IgorPI

Try to ignore the error
- docker stop $CI_PROJECT_NAME || true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question