3

I perform the following docker commands in the following order:

docker pull docker

docker run -ti <imgId>

https://hub.docker.com/_/docker/

Now I am inside the "docker" image for Docker

Now suppose I create a temp folder and download a Dockerfile

mkdir temp

cd temp

curl <dockerfile>

docker build .

It will tell me Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

This means that the docker service needs to be started, but as the official docker image comes on alpine linux, commands like service/systemctl are not available, so we must perform apk add openrc --no-cache to access these.

After I install it, I still cannot start the docker service.

Performing system docker start says that it cannot find docker as a service?

service: service docker does not exist

Eventually I want to build this via Jenkins.

enter image description here

In the build step, I perform Execute Shell

if [ -f "Dockerfile" ]; then
    echo "Dockerfile exists ... removing it"
    rm Dockerfile
fi

wget <dockerFile url>


docker build .

I purposely don't do the openrc on Jenkins since I want to test locally first

K Split X
  • 3,405
  • 7
  • 24
  • 49
  • Is your Jenkins inside a container? – prisar Aug 27 '18 at 18:51
  • Yes, my Jenkins pulls the docker image from our proxy – K Split X Aug 27 '18 at 18:53
  • @ps4, I added an image for your preference – K Split X Aug 27 '18 at 18:56
  • To a first approximation, commands like `service` and `systemctl` just don't work at all in Docker. Running Docker as a container is a particularly advanced setup, and generally disrecommended; usually you'd configure Jenkins to use the host's Docker socket. – David Maze Aug 27 '18 at 18:59
  • Using Jenkins to use the dockers host socket requires that the Jenkins service be installed on the Linux Slave, which is not the approach we are going for. I'm wondering what I am doing wrong here though? The official image should have docker installed – K Split X Aug 27 '18 at 19:04
  • Using the `docker` image is probably wrong. The [Docker Hub page for the image](https://hub.docker.com/_/docker/) says so too, though not quite as bluntly. – David Maze Aug 27 '18 at 19:33
  • It is not recommended, but it is a requirement here – K Split X Aug 28 '18 at 12:44

1 Answers1

0

The image you're pulling here (with the latest tag) does not contain the docker daemon. It's meant to be used as the docker client. What you want is to first get the docker daemon running with the image tagged dind (docker in docker).

docker network create dind
docker run --privileged --name docker --network dind -v docker-client-certs:/certs/client -d docker:dind

To verify it started up and works, you can check the logs.

docker logs docker

Now you can use a client container to connect to the daemon. This is how you connect interactively to the shell, like you wanted to:

docker run -ti --network dind -e DOCKER_TLS_CERTDIR=/certs -v docker-client-certs:/certs/client:ro docker

Docker commands should work inside this container. If you do docker version, you should see the versions of both the client and the server.

Note the two containers share the same network (some examples online feature links, but those are deprecated). They also share some of the TLS certs, which are generated when starting up the dind image.

uint
  • 1
  • 1
  • 1