blacklabelops/swarm-dockerhost

By blacklabelops

Updated almost 7 years ago

Test container for accessing the docker demon on the host.

Image

3.5K

Jenkins Slave Container With Docker

Rule #1 Read the WARNING!

Rule #2 Read the WARNING!

Rule #3 Just read the WARNING!

WARNING

Anyone who can execute docker commands on this slave will be able to execute root commands on your host! In worst case they can manipulate or just delete your machine! Only use this when you know what you do!

Make It Short!

In short, you can use Docker CLI commands inside a Jenkins slave.

First start a master!

$ docker run -d -p 8090:8080 --name jenkins blacklabelops/jenkins

This will pull the my jenkins container ready with swarm plugin and ready-to-use!

Now start the build slave!

$ docker run -d \
    -v /var/run/docker.sock:/var/run/docker.sock \
    --link jenkins:jenkins \
    blacklabelops/swarm-dockerhost

CLI commands will be available.

How It Works

Check this project on how to configure a swarm slave: blacklabelops/jenkins-swarm

Docker Login

The slave can be started and login in a remote repository. The default is the dockerhub registry.

With the environment variables:

  • DOCKER_REGISTRY_USER: Your account username for the registry. (mandatory)
  • DOCKER_REGISTRY_EMAIL: Your account email for the registry. (mandatory)
  • DOCKER_REGISTRY_PASSWORD: Your account password for the registry. (mandatory)

Example:

$ docker run -d \
    --link jenkins:jenkins \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -e "DOCKER_REGISTRY_USER=**Your_Account_Username**" \
    -e "DOCKER_REGISTRY_EMAIL=**Your_Account_Email**" \
    -e "DOCKER_REGISTRY_PASSWORD=**Your_Account_Password**" \
    blacklabelops/swarm-dockerhost

Will login the user to Dockerhub and save the credentials locally for repository pulls and pushes.

Changing the Docker registry

The default for this container is dockerhub.io. If you want to use another remote repository, e.g. quay.io then Your_Account_Email can specify the repository with the environment variable DOCKER_REGISTRY.

Example:

$ docker run -d \
    --link jenkins:jenkins \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -e "DOCKER_REGISTRY=quay.io"
    -e "DOCKER_REGISTRY_USER=**Your_Account_Username**" \
    -e "DOCKER_REGISTRY_EMAIL=**Your_Account_Email**" \
    -e "DOCKER_REGISTRY_PASSWORD=**Your_Account_Password**" \
    blacklabelops/swarm-dockerhost

Will login to quay.io with the specified credentials.

References

Docker Pull Command

docker pull blacklabelops/swarm-dockerhost