I followed how to builf the docker image from: https://gitlab.com/guided-explorations/containers/kaniko-docker-build/-/blob/master/.gitlab-ci.yml
The job works and throws no error when tested using gitlab from browser.
But now I want to be able to run the image as a container with some command
The build section in .gitlab-ci.yml
build-repo:
extends: .build_with_kaniko
environment:
name: push-to-repo-registry
tags:
- shared-runner-tag
What do I need to add to the .gitlab-ci.yml
file to be able to run the image as a container with a command like I would from the terminal:
$sudo docker run --name <image_instance> -i -t <image_name> [some command]
I'm just looking for a quick solution on how to run the image as a container. Every guide with regards to kaniko (I have to use it for my case) only speaks about building the image and pushing it to docker and the gitlab registry, but never on how to run it.
Thank You
In .gitlab-ci.yml, you can execute docker command on remote server using option -H or environment variable DOCKER_HOST. You can find the documentation to enable TLS and execute command on remote host here.
export DOCKER_HOST=tcp://<host>:<port>
export DOCKER_CERT_PATH=<certificate_dir>
export DOCKER_TLS_VERIFY=1
docker run -d <image>
EDIT: Of course, you need to have docker installed in your gitlab runner.