When I was investigating the cause of moss in Job that builds docker image with GitLab CI, I found that it was moss when I did docker info
.
docker is a client-server application, but if you type the docker info
command before the docker daemon on the server side starts, you will get angry with" I don't have a daemon ... ".
Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?
The docker in docker dind
is used correctly, and it's really just a delay in booting, so if you wait like sleep 10
, the build will pass. However, I don't want to put on a mysterious sleep, so I want to wait until the daemon starts.
I wrote a shell script and added it to the project. Fortunately, I know that docker info will fail without daemon, so I will use it.
wait.sh
#!/bin/sh
#A script that waits for the dind docker daemon to start
while :
do
if docker info > /dev/null 2>&1; then
break
fi
echo 'waiting docker daemon...'
sleep 1
done
exit 0
Put the script before docker info
in .gitlab-ci.yml. Don't forget chmod to make it executable.
yml:.gitlab-ci.yml
before_script:
- chmod u+x wait.sh && ./wait.sh
- docker info
The build no longer fails because it waits for startup.
Recommended Posts