You may or may not want to change only: pushes to only: tags in the ci file, but other than that you'll also need to set DOCKER_CI_HOST in gitlab group variables to the server address of the listening docker server as well as DOCKER_PROJECT_PORT in the gitlab project variables to the port you want to expose your app on. This also assumes that you have allowed docker to run on port 2375 remotely and not just locally via the sock file.
Last active
October 2, 2020 04:33
-
-
Save theoparis/1ac16c3af1a022f4380d37e33d028fa9 to your computer and use it in GitHub Desktop.
gitlab ci - deploy to remote docker server and run image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: docker:stable | |
stages: | |
- deploy | |
docker push latest: | |
stage: deploy | |
only: | |
- pushes | |
script: | |
- DOCKER_HOST=$DOCKER_CI_HOST:2375 docker build -t $CI_PROJECT_NAMESPACE-$CI_PROJECT_ID . | |
- DOCKER_HOST=$DOCKER_CI_HOST:2375 docker stop $CI_PROJECT_NAMESPACE-$CI_PROJECT_ID || true | |
- DOCKER_HOST=$DOCKER_CI_HOST:2375 docker rm $CI_PROJECT_NAMESPACE-$CI_PROJECT_ID || true | |
- DOCKER_HOST=$DOCKER_CI_HOST:2375 docker run -d -p $DOCKER_PROJECT_PORT:3000 --name $CI_PROJECT_NAMESPACE-$CI_PROJECT_ID $CI_PROJECT_NAMESPACE-$CI_PROJECT_ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment