I cannot use the docker plugin because I need to run tests on my Docker image after I build it before I can safely push it to my Docker registry. However, I have used the Docker plugin with great success, with secrets, but this doesn’t solve my problem.
I have seen that you can mount the docker.sock file as a volume from the host machine (the so-called “Docker-near-Docker” method). That works also if I mark my repo as “trusted”, however doing this does not pass in the docker credentials from the host to the container itself.
The only way I can think of doing this is to invoke the “docker login” command with the username and password, which I have stored as secrets for that image and repo. However, this does not work.
My pipeline is shown below.
pipeline:
build:
image: docker
volumes:
- /var/run/docker.sock:/var/run/docker.sock
commands:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- docker build -t myorg/drone-slave .
- docker run myorg/drone-slave /usr/local/bin/bats /test/test.bats
- docker push myorg/drone-slave
Returns:
+ docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
inappropriate ioctl for device
How can I do this?