I want to run sentry-cli inside my docker image like this:
sentry-frontend:
stage: sentry
services:
- docker:18-dind
before_script:
- docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" registry.xxx.xx
script:
- export SENTRY_AUTH_TOKEN=xxxxxxxxxxxxxxxxxx
- export IMAGE=$CI_REGISTRY_IMAGE/frontend-builder:$CI_COMMIT_REF_NAME
- export RELEASE_VERSION=$CI_COMMIT_REF_NAME
- docker pull getsentry/sentry-cli
- docker run --rm -v $(pwd):/work getsentry/sentry-cli releases -o org -p frontend new $RELEASE_VERSION
tags:
- dind
However the job fails because
error: API request failed
caused by: sentry reported an error: Authentication credentials were not provided. (http status: 401)
I tried:
- docker run --rm -v $(pwd):/work getsentry/sentry-cli --auth-token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
however after that I get the same message as I would if I ran
docker run --rm -v $(pwd):/work sentry-cli --help
and after that it fails as if the command was not correct.I can't seem to find any information on how to do that correctly either. How to provide credentials inside that image?
If you want to pass the SENTRY_AUTH_TOKEN environment variable to the container, you can adapt your docker run command like this:
docker run --rm -v "$PWD:/work" -e SENTRY_AUTH_TOKEN="$SENTRY_AUTH_TOKEN" getsentry/sentry-cli releases -o org -p frontend new $RELEASE_VERSION
or more concisely:
docker run --rm -v "$PWD:/work" -e SENTRY_AUTH_TOKEN getsentry/sentry-cli releases -o org -p frontend new $RELEASE_VERSION
(but note that the latter version won't work if docker is an alias of sudo docker)
The relevant documentation page is:
docs.docker.com/engine/reference/commandline/run/
As an aside, note that -v "$PWD:/work" is more efficient than -v "$(pwd):/work" (one less process to spin).
Related
Im trying to run docker inside jenkins container, i used this command to create jenkins container
docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker jenkins/jenkins:latest
then this command to access jenkins container bash
docker exec -u 0 -it <container-id> bash, whenever i run docker i get this error
docker: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by docker) docker: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by docker)
What is creating this problem and what ways in order to solve it ?
This is not reliable anymore, because the Docker Engine is no longer distributed as (almost) static libraries.
so run docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins:latest
then this command to access jenkins container bash as root user docker exec -u 0 -it <container-id> bash
Once inside the Jenkins container, simply run this command to install docker inside of the Jenkins container: curl https://get.docker.com/ > dockerinstall && chmod 777 dockerinstall && ./dockerinstall
this command gets the docker quick installation script and runs the script which then installs docker inside of the container
Exit out of the Jenkins container interactive shell, and run the following command to change permissions on “docker.sock” for added security sudo chmod 666 /var/run/docker.sock
solved by downgrading my server OS to Ubuntu 18
I have two jobs, 'build' and 'test'. 'build' job builds and runs the docker image. I'm able to access the url http://0.0.0.0:3000 to run my tests from the same job. But when I run my tests from 'test' job, it doesn't recognize http://0.0.0.0:3000.
jobs:
build:
.
.<other code>
.
steps:
- run:
docker build . -t company/project:${CIRCLE_SHA1}
docker run --net=host -e DOPPLER_TOKEN=${DOPPLER_TOKEN} -d company/project:${CIRCLE_SHA1} "npm run dev"
docker run --net=host -v ~/projects/project_name/tests/:/tests -v ~/projects/project_name/node_modules/:/node_modules -it testcafe/testcafe chromium:headless
The above code seems to run perfectly fine.
jobs:
build:
.
.<other code>
.
steps:
- run:
docker build . -t company/project:${CIRCLE_SHA1}
docker run --net=host -e DOPPLER_TOKEN=${DOPPLER_TOKEN} -d company/project:${CIRCLE_SHA1} "npm run dev"
test:
working_directory: ~/projects/project_name
machine: true
steps:
- checkout
- run:
docker run --net=host -v ~/projects/project_name/tests/:/tests -v ~/projects/project_name/node_modules/:/node_modules -it testcafe/testcafe chromium:headless
This doesn't work. It gives an error
A request to "http://0.0.0.0:3000" has failed. You can find troubleshooting information for this issue at "https://go.devexpress.com/TestCafe_FAQ_ARequestHasFailed.aspx". Error details: Failed to find a DNS-record for the resource at "http://0.0.0.0:3000"
I've also tried the curl command to access the url and it gives an error
curl -o - http://0.0.0.0:3000 curl: (7) Failed to connect to 0.0.0.0 port 3000: Connection refused
Any help regarding this would be very helpful.
I ran the docker run command to run the jenkins image.
But this is the command that was executed in the past, but now an error occurs.
command
docker run -u root —rm -p 8080:8080 —name jenkins \ -v Users/human/jenkins:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \ jenkins
error
docker: invalid reference format.
See 'docker run --help'.
My environment is Mac OS X. What's wrong with me?
It could be the path "Users/human/jenkins" is invalid. If you are using $PWD following the example on Jenkins site, be very careful about possible space character in the "current" path. That would mess up the command and throw out that error message you posted.
It seems like you have a parsing issue for the command above, I have changed this — to --.. this should work:
docker run -u root --rm -p 8080:8080 --name jenkins -v Users/human/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins
Or like this:
docker run -u root --rm -p 8080:8080 --name jenkins \
-v Users/human/jenkins:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkins
After setting up gitlab-runner as a Docker container with an executor of docker, I fail to run any builds. The displayed log reads like the following:
Running with gitlab-runner 11.4.2 (cf91d5e1)
on <hostname> 9f1c1a0d
Using Docker executor with image docker:stable-git ...
Starting service docker:stable-dind ...
Pulling docker image docker:stable-dind ...
Using docker image sha256:acfec978837639b4230111b35a775a67ccbc2b08b442c1ae2cca4e95c3e6d08a for docker:stable-dind ...
Waiting for services to be up and running...
Pulling docker image docker:stable-git ...
Using docker image sha256:a8a2d0da40bc37344c35ab723d4081a5ef6122d466bf0a0409f742ffc09c43b9 for docker:stable-git ...
Running on runner-9f1c1a0d-project-1-concurrent-0 via a7b6a57c58f8...
Fetching changes...
HEAD is now at 5430a3d <Commit message>
Checking out 5430a3d8 as master...
Skipping Git submodules setup
$ # Auto DevOps variables and functions # collapsed multi-line command
$ setup_docker
$ build
Logging to GitLab Container Registry with CI credentials...
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password
ERROR: Job failed: exit code 1
Note the attempt to ligin to docker-hub (I guess) and the credentials-error. But I do not desire nor configured a username/password to access docker-hub. Any suggestion what is wrong here or how to go on debugging this?
The runner was registered with the following command (which also dictates the contents of the configuration file):
docker run --rm -ti \
-v <config-volume>:/etc/gitlab-runner \
-v $(pwd)/self-signed-server.crt:/etc/ssl/certs/server.crt \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner register \
--tls-ca-file /etc/ssl/certs/server.crt \
--url https://my.server.url/gitlab/ --registration-token <token> \
--name myserver --tag-list "" \
--executor docker --docker-privileged --docker-image debian \
--non-interactive
I used --docker-privileged because I originally had the same problem discussed here (thanks, wendellmva). I just can't configure running the gitlab-runner container itself privileged, but don't see link-failure-problem problem even though I don't.
To get past this point, one needs to overwrite the CI_REGISTRY_USER variable in the projects Settings -> CI / CD -> Variables block. Assigning an empty value will get past this point.
Background: by exporting the project and then parsing the JSON settings with jq, one can get the preconfigured list of commands that run:
jq -r .pipelines[0].stages[0].statuses[0].commands project.json
# ...
function registry_login() {
if [[ -n "$CI_REGISTRY_USER" ]]; then
echo "Logging to GitLab Container Registry with CI credentials..."
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
echo ""
fi
}
# ...
So there is apparently some non-empty string preloaded to CI_REGISTRY_USER, but with an invalid CI_REGISTRY_PASSWORD.
What I haven't found yet is where to make such settings globally for all projects or how to edit the AutoDevOps pipeline.
I have the following .gitlab-ci.yml task for an elixir project:
image: docker:latest
services:
- docker:dind
stages:
- build
- test
- release
- deploy
variables:
TEMP_IMAGE: registry.gitlab.com/farmmix/homepage/farmmix_homepage:$CI_COMMIT_SHA
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
build:
stage: build
script:
- cd src
- docker build --pull -t $TEMP_IMAGE .
- docker push $TEMP_IMAGE
test:
stage: test
variables:
DB_DATABASE: test
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_URL: postgres
script:
- echo $TEMP_IMAGE
- docker pull $TEMP_IMAGE
- docker pull postgres:9.5-alpine
- docker run --name postgres -e POSTGRES_DB=$DB_DATABASE -e POSTGRES_USER=$DB_USERNAME -e POSTGRES_PASSWORD=$DB_PASSWORD -d postgres:9.5-alpine
- docker run --link postgres $TEMP_IMAGE ecto.create ecto.migrate test
The $TEMP_IMAGE is an existing image that gets created at a previous build task.
If I run it locally with gitlab-runner exec docker --docker-privileged test, it works fine.
However, gitlab runner gives me the following:
... AFTER INITIALIZATION ...
Skipping Git submodules setup
$ docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded
$ echo $TEMP_IMAGE
registry.gitlab.com/farmmix/homepage/farmmix_homepage:b0c30097a320933f7d5390d7037960e34d2ef7d
$ docker pull $TEMP_IMAGE
b0c30097a320933f7d5390d7037960e34d2ef7d0: Pulling from farmmix/homepage/farmmix_homepage
605ce1bd3f31: Pulling fs layer
...
e0c7f5df971a: Pull complete
Digest: sha256:ce7a1bf2378628902e171a22ee386af6c79e8d2340b6241ab70e83173e32ce28
Status: Downloaded newer image for registry.gitlab.com/farmmix/homepage/farmmix_homepage:b0c30097a320933f7d5390d7037960e34d2ef7d0
$ docker pull postgres:9.5-alpine
9.5-alpine: Pulling from library/postgres
550fe1bea624: Pulling fs layer
04bf519c70df: Pulling fs layer
...
0dca1c6b5036: Pull complete
Digest: sha256:fc3b8fcc8ba568492ce89fd8723a949f586e2919d7884b9b1d8064237ba105d7
Status: Downloaded newer image for postgres:9.5-alpine
$ docker run --name postgres -e POSTGRES_DB=$DB_DATABASE -e POSTGRES_USER=$DB_USERNAME -e POSTGRES_PASSWORD=$DB_PASSWORD -d postgres:9.5-alpine
Unable to find image 'of:latest' locally
docker: Error response from daemon: pull access denied for of, repository does not exist or may require 'docker login'.
See 'docker run --help'.
ERROR: Job failed: exit code 125
I cannot even find anything on the internet of this 'of:latest' error. I tried running the docker run command without the -e arguments but the same error appeared so it's not that the env vars are causing any trouble.
I'm running out of ideas. Do any of you guys suspect what the solution might be?
EDIT: Added complete .gitlab-ci.yml content
EDIT2: Added echo and output of job
$ docker run --name postgres -e POSTGRES_DB=$DB_DATABASE -e POSTGRES_USER=$DB_USERNAME -e POSTGRES_PASSWORD=$DB_PASSWORD -d postgres:9.5-alpine
Unable to find image 'of:latest' locally
docker: Error response from daemon: pull access denied for of, repository does not exist or may require 'docker login'.
One of your variables almost certainly contains the string " of " in it. You could test this by adding a line:
echo docker run --name postgres -e POSTGRES_DB=$DB_DATABASE -e POSTGRES_USER=$DB_USERNAME -e POSTGRES_PASSWORD=$DB_PASSWORD -d postgres:9.5-alpine
first to see what it's trying to run. With variables, it's a good practice to quote them to avoid any issues with special characters or spaces:
docker run --name postgres -e "POSTGRES_DB=$DB_DATABASE" -e "POSTGRES_USER=$DB_USERNAME" -e "POSTGRES_PASSWORD=$DB_PASSWORD" -d postgres:9.5-alpine