I launched a Docker container with Terraform, simple code.
> cat main.tf
provider "docker"{
}
resource "docker_image" "ubuntu"{
name = "ubuntu:latest"
}
resource "docker_container" "webserver" {
image = "${docker_image.ubuntu.latest}"
name = "dev-web-p01"
#start = true
must_run = true
publish_all_ports = true
}
I can see the container spun up but not running.
> docker container -ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63c770e28ad2 47b19964fb50 "/bin/bash" 10 minutes ago Exited (0) 3 minutes ago dev-web-p01
My attempt to start and connect to the container fails and I am not sure why?
> docker container start 63c
63c
> docker container exec -it 63c /bin/bash
Error response from daemon: Container 63c770e28ad256e77442cb2fb8b9b8bbc14b8f37b99296bc63f2d249209e0399 is not running
I have tried this for a couple of times but it doesn't work. Sorry bit of a noob here.
Exited (0) means program successfully completed. With docker you need to execute some long running commands to ensure it doesn't finish immediately.
Best way to test some changes with docker, is waiting for nothing. Try this:
resource "docker_image" "ubuntu" {
name = "ubuntu:latest"
}
resource "docker_container" "webserver" {
image = "${docker_image.ubuntu.latest}"
name = "terraform-docker-test"
must_run = true
publish_all_ports = true
command = [
"tail",
"-f",
"/dev/null"
]
}
Related
I'm trying to execute a docker container with a Cloudera quickstart image in Windows 11.
I followed the tutorial in the page https://hub.docker.com/r/cloudera/quickstart/.
When I execute the image from docker dash I received the error "Error invoking remote method 'docker-run-container': Error: (HTTP code 400) unexpected - No command specified".
There is no log.
My Docker app is updated - Docker Desktop 4.5.1 (74721).
I did the image download from command:
docker pull cloudera/quickstart:latest
REPOSITORY TAG IMAGE ID CREATED SIZE
docker/getting-started latest bd9a9f733898 3 weeks ago 28.8MB
cloudera/quickstart latest 4239cd2958c6 5 years ago 6.34GB
The container is created
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4242480d0804 4239cd2958c6 "/usr/bin/docker-qui…" 5 minutes ago Exited (139) 4 minutes ago charming_buck
6b3e7313b8e9 docker/getting-started "/docker-entrypoint.…" 2 days ago Exited (0) 2 hours ago interesting_ptolemy
I've seen some similar questions with some answers like change the .wslconfig file, I did it but I got same error.
{
"builder": {
"gc": {
"defaultKeepStorage": "8GB",
"enabled": true
}
},
"experimental": false,
"features": {
"buildkit": true
}
}
But with no result. Is there anyone could help me?
Thank you!!
1: to start the container run
docker run --hostname=quickstart.cloudera --privileged=true -it cloudera/quickstart /usr/bin/docker-quickstart
Note 1: /usr/bin/docker-quickstart is provided as a convenience to start all CDH services, then run a Bash shell. You can directly run /bin/bash instead if you wish to start services manually.
Note: 2 A container will die when you exit the shell, but you can disconnect and leave the container running by hitting Ctrl+P -> Ctrl+Q.
I have a Gitlab-Runner (version: 14.4.0) in a VM (Ubuntu). The docker version is 20.10.10.
Everything was working as expected.
Then I wanted to delete the installed images in the folder "/var/lib/docker/vfs".
I have done the following steps.
systemctl stop docker
cd /usr/share/gitlab-runner
./clear-docker-cache prune
docker system prune -f --all
ls -la /var/lib/docker/vfs/dir/
# returns an empty dir which is what I want
systemctl daemon-reload
systemctl start docker
systemctl stop gitlab-runner
systemctl start gitlab-runner
After that I tried to start a new build job using this gitlab-runner. Unfortunately, the Gitlab runner continues to reference the images I`ve deleted.
The following error messages occur when I want to build something with the runner.
Using Docker executor with image my-alpine:0.1.6 ...
ERROR: Preparation failed: adding cache volume: set volume permissions: create permission container for volume "runner-o19hepv1-project-133520-concurrent-0-cache-3c3f060a0374fc8bc39395164f415a70": Error response from daemon: 48ac0f992674b920004317b8b6fc91dbc72f01327ca96005f7b19693f3c128ca: stat /var/lib/docker/vfs/dir/48ac0f992674b920004317b8b6fc91dbc72f01327ca96005f7b19693f3c128ca: no such file or directory (linux_set.go:95:0s)
How do I get rid of these error messages?
What did I do wrong with my approach. In principle, I would also like the images to be deleted once a week later.
The gitlab-runner systemd service is started with
/usr/bin/gitlab-runner "run" "--working-directory" "/home/gitlab-runner" "--config" "/etc/gitlab-runner/config.toml" "--service" "gitlab-runner" "--user" "gitlab-runner"
and the configuration (config.toml) is
concurrent = 5
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "my-gitlabrunner"
url = "https://git.tech.rz.db.de/"
token = "mytoken"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "alpine"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
I had a similar problem and, in my case, this was caused when the runner tried to crate a "permissions container" using a faulty image. Deleting that image so that it would re-download sorted it for me, the image was called registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-8925d9a0
$ docker image rm registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-8925d9a0
Error response from daemon: exit status 1: "/usr/bin/zfs fs destroy -r system/docker/418e78d27d51c2e2628534aaf9f84c5d76748d62e548a4de356328e0fb3a0c31" => cannot open 'system/docker/418e78d27d51c2e2628534aaf9f84c5d76748d62e548a4de356328e0fb3a0c31': dataset does not exist
Despite the error message the image was deleted. When I then retried a CI job it was downloaded again and everything has worked fine since.
In docker we have -t flag to keep containers from exiting. How can achieve the same thing in nomad?
I want to debug if I can ping one service from another, so I just want a container with curl. However, if I try to deploy the ubuntu image specifying it like below it exits and keeps restarting. What can I do so it just keeps running?
task "testubuntu" {
driver = "docker"
config {
image = "ubuntu:latest"
}
resources {
cpu = 500
memory = 256
network {
mbits = 10
}
}
}
Another solution would be to set a "dummy" entry point tail -f /dev/null
task "testubuntu" {
driver = "docker"
config {
image = "ubuntu:latest"
entrypoint = [
"tail", "-f", "/dev/null",
]
}
resources {
cpu = 500
memory = 256
}
}
It is particularly useful, when you have a task that errors at the container startup but there is not much useful information in the logs. This "dummy" entry point will keep container alive allowing you to get inside container and execute a real startup command with attached debugger for example.
Apart from tail -f /dev/null, you can also simply use yes as an entry point. However, it will pollute stdout and affect your logging solution if it is setup.
Add container = true in the config stanza
task "testubuntu" {
driver = "docker"
config {
image = "ubuntu:latest"
container = true
}
resources {
cpu = 500
memory = 256
network {
mbits = 10
}
}
}
I want to setup CI/CD in GitLab.
So i installed docker and the gitlab-runner on linux, created a config for a runner and started everything. So far so good.
The runner works, and docker works.
But i am using the linux subsystem from windows, so i need to run the docker container with parameter "--network host" otherwise they not gonna work.
So right now i try to configure the gitlab-runner to use the host network via the "network_mode" parameter. But it does not work. I get the same error as if i would run a docker container directly and without the "--network host".
The error:
WARNING: Preparation failed: Error response from daemon: oci runtime error: container_linux.go:265: starting container process caused "process_linux.go:368: container init caused \"process_linux.go:351: running prestart hook 0 caused \\"error running hook: exit status 1, stdout: , stderr: time=\\\\"2019-04-12T18:42:33+02:00\\\\" level=fatal msg=\\\\"failed to add interface vethfc7c8d1 to sandbox: failed to get link by name \\\\\\\\"vethfc7c8d1\\\\\\\\": Link not found\\\\" \\n\\"\"" (executor_docker.go:423:16s) job=123project=123 runner=123
This is my config:
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "MyHostName"
url = "https://my.gitlab.url/"
token = "SoMeFaNcYcOdE-e"
executor = "docker"
[runners.docker]
tls_verify = false
image = "beevelop/ionic:latest"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
network_mode = "host"
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
My question is how do i force the gitlab runner to create the containers to use the host network like with the docker parameter: "--network host"
I was unable to solve the problem directly, but i found an alternative way which is a lot better.
I configured the GitLab Container Registry
of the repository to upload and white list a custom docker image and then enabled the Shared Runners of my company. The custom image i uploaded was created via a Dockerfile using docker for windows, avoiding the struggle of the buggy docker in the linux subsystem of windows. Now i can execute my CI pipeline flawlessly and have full control over the used image and do not have to keep my local machine running.
I am new bie to gitlab-runner, i have tried to setup gitlab-runner-autoscaling but i am unable to download ecr images in a build. When i try to ssh into docker-machine i am able to download images, i even tried to ssh into the VM and tried to pull ecr images as root and as ubuntu user(ubuntu 16.04 AMI), it only fails while running a build .
Please let me know how i can troubleshoot.
1. How can i find the command gitlab-runner is using to pull ecr image/
2. How to find the user its running the docker command.
Runner config:
[[runners]]
name = "registry-test4"
limit = 1
url = "http://gitlab.xxxxxxxx.com/"
token = "xxxxxxxxxxxxxxx"
executor = "docker+machine"
[runners.docker]
tls_verify = false
image = "ruby:2.1"
privileged = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[runners.cache]
[runners.machine]
IdleCount = 1
MachineDriver = "amazonec2"
MachineName = "gitlab-runner-ci-%s"
MachineOptions = ["amazonec2-iam-instance-profile=xxxxxxxxxxx", "amazonec2-ssh-user=ubuntu", "amazonec2-region=us-east-1", "amazonec2-instance-type=t2.large", "amazonec2-ami=ami-xxxxx", "amazonec2-vpc-id=vpc-xxxxx", "amazonec2-subnet-id=subnet-xxxxx", "amazonec2-zone=a", "amazonec2-root-size=32", "amazonec2-keypair-name=spot", "amazonec2-ssh-keypath=/root/.ssh/spot", "amazonec2-userdata=/etc/gitlab-runner/bootstrap.sh", "amazonec2-request-spot-instance=true", "amazonec2-security-group=docker_machine_git_as_prod", "amazonec2-security-group=consul-agent-prod", "amazonec2-private-address-only", "amazonec2-spot-price=x.xx"]
OffPeakPeriods = ["* * 5-11 * * mon-fri *", "* * * * * sat,sun *"]
OffPeakTimezone = ""
OffPeakIdleCount = 1
OffPeakIdleTime = 1200
Error:
Running with gitlab-runner 10.2.0 (0a75cdd1)
on registry-test4 (31b91ac3)
Using Docker executor with image xxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/dev/sbt:latest ...
Using docker image sha256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxfor predefined container...
Pulling docker image xxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/dev/sbt:latest ...
ERROR: Preparation failed: Error response from daemon: Get https://xxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/v2/dev/sbt/manifests/latest: no basic auth credentials
Will be retried in 3s ...
.gitlab-ci.yml
---
main:
image: xxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/dev/sbt:latest
script: sbt +runCI
Solved this issue , by installing ecr binary
https://github.com/awslabs/amazon-ecr-credential-helper
on gitlab-runner server passing these parameters in /root/.docker/config.json. (earlier ecr was installed only on the VM docker-machine was provisioning.)
{
"credsStore": "ecr-login"
}