dockerjenkinsdocker-composedockerfiledocker-engine

Docker - Is volume mapping of socket file an override behavior?


Below is the code snippet of jenkins image taken from here:

# Install Docker Engine
RUN apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D && \
    echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | tee /etc/apt/sources.list.d/docker.list && \
    apt-get update -y && \
    apt-get purge lxc-docker* -y && \
    apt-get install docker-engine=${DOCKER_ENGINE:-1.10.2}-0~trusty -y && \
    usermod -aG docker jenkins && \
    usermod -aG users jenkins

that installs docker engine within jenkins image. My understanding is, var/run/docker.sock is created withing Jenkins container, due to installation of docker engine.


Below is the volume mapping syntax taken from here:

volumes:
  - jenkins_home:/var/jenkins_home
  - /var/run/docker.sock:/var/run/docker.sock

that launches jenkins container(above) on EC2 host.

EC2 host also has docker daemon running.

So, there is docker daemon running in EC2 host. There is also a docker daemon running within docker container(Jenkins)


With this syntax(/var/run/docker.sock:/var/run/docker.sock) in docker-compose(above) for socket files,

Does docker daemon within Jenkins container override its own socket file with the socket file present in EC2 host? If yes... what is its implication?


Solution

  • From the docs:

    Docker-engine is a client-server application

    Please note that when you install docker-engine you install docker-daemon (server) and docker cli (client).

    It means that if a docker daemon isn't running you will still be able run docker cli commands:

    docker info
    Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
    

    Jenkins image you shared doesn't have instructions to run docker engine. So i assume it's not running inside the container.

    /var/run/docker.sock:/var/run/docker.sock volume maps docker host's docker engine socket to the container.

    So docker cli commands run within the container control the docker-engine running on the docker host.

    This makes sense if you do CI/CD on your host from within containerized Jenkins.

    Jenkins pipelines may use docker, docker-compose and docker swarm commands to run tests, build artifacts and deploy new versions of applications.