Run docker container on server

With my configuration the dind build sends the app to the docker registry. On the server I can execute docker pull and docker run. The container then runs and is accessible permanent on the server directly. In Gitlab the jobs “test” runs it only in dind and do not make it permanent accessible. How do I have to structure my pipeline?

My CI/CD Pipeline gitlab-ci.yml:
image: docker:latest
services:

  • docker:dind

stages: # List of stages for jobs, and their order of execution

  • build
  • test

before_script:

  • docker login -u gitlab-ci -p $CI_BUILD_TOKEN $CI_REGISTRY

docker_build:
stage: build
script:

  • docker pull $CI_REGISTRY_IMAGE:latest || true
  • docker build --cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA -t $CI_REGISTRY_IMAGE:latest .
  • docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
  • docker push $CI_REGISTRY_IMAGE:latest

docker_test:
stage: test # It only starts when the job in the build stage completes successfully.
before_script:
- docker stop $CI_PROJECT_NAME || true
- docker rm $CI_PROJECT_NAME || true
- docker rmi $CI_REGISTRY_IMAGE:latest || true
- docker pull $CI_REGISTRY_IMAGE:latest
script:

  • docker run --privileged --name $CI_PROJECT_NAME -d -p 8000:8000 --restart unless-stopped $CI_REGISTRY_IMAGE:latest