When executing docker-compose up --build
I get the error FATAL: Command <COMMAND> not found.
My docker-compose.yaml file.
version: '3'
services:
gitlab-runner:
container_name: gitlab-runner
image: gitlab/gitlab-runner:v15.8.2
volumes:
- ./config:/etc/gitlab-runner
- ./sock:/var/run/docker.sock
command: bash -c "echo '123.123.255.11 adc.cde.com' >> /etc/hosts"
The command i put there does not really matter. I get the same error for every command I've tried so far (ls
, cd
, /bin/bash
, sh
, /bin/sh
, or a shell script I copied to a volume).
How do I get this to execute?
As a side node: Is there another way i could automatically modify a file on container-startup?
Docker Compose version 2.22.0 used image: gitlab/gitlab-runner:v15.8.2
I know for a fact, that bash is available on this image, since docker exec -it <container> bash
does work (as well as all the other things I listed).
The image gitlab/gitlab-runner:v15.8.2
defines an ENTRYPOINT
script:
$ docker image inspect gitlab/gitlab-runner:v15.8.2
...
"Entrypoint": [
"/usr/bin/dumb-init",
"/entrypoint"
],
...
The entrypoint script ultimately runs:
exec gitlab-runner "$@"
So when you set:
command: /usr/bin/bash -c "echo '123.123.255.11 adc.cde.com' >> /etc/hosts"
You are actually running:
gitlab-runner /usr/bin/bash -c "echo ..."
And /usr/bin/bash
isn't a valid gitlab-runner
command, hence the error.
Ignoring all of the above, there's a more fundamental problem with your current configuration. If it worked as you intended and ran the bash
command line, the container would simply exit immediately (because a container exists when the initial command exits).
For what you're trying to do, the simplest solution is to use the extra_hosts
option in your compose file:
services:
gitlab-runner:
container_name: gitlab-runner
image: gitlab/gitlab-runner:v15.8.2
volumes:
- ./config:/etc/gitlab-runner
- ./sock:/var/run/docker.sock
extra_hosts:
- adc.cde.com:123.123.255.11
Once the container is running, we see:
$ docker exec gitlab-runner cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
123.123.255.11 adc.cde.com
172.27.0.2 61da9a89d42f