gaurav
gaurav

Reputation: 431

How to Bootstrap from Workstaion to Docker conatiner?

I want to run a role on docker container .How can i achieve it ??

Any syntax of command will be helpful.

knife bootstrap -x -P like this

Thanks

Upvotes: 0

Views: 1466

Answers (1)

Javier Cortejoso
Javier Cortejoso

Reputation: 9176

Having a container with ssh access, you can use knife bootstrap. For example:

CONTAINER=$(docker run -d -e ROOT_PASS="mypass" tutum/ubuntu:trusty)
CONTAINERIP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CONTAINER})
knife bootstrap $CONTAINERIP -x root -P mypass --sudo -r 'role[myrole]'

The first line will run a docker container (image tutum/ubuntu:trusty) with ssh daemon enabled, and root ssh password set to "mypass". The CONTAINER_ID of this image is returned by docker run command and saved to CONTAINER variable.

The second command will use this CONTAINER_ID to get the IP address assigned to this conteiner, and save it to CONTAINERIP variable.

And the third command bootstraps chef in the container, using the $CONTAINERIP variable to reference its ip, and the ssh credentials of the container. This works supposed you have configured knife correctly.

Note about SSH: The container you use has to have a daemon ssh running. In docker docs there are references to this (http://docs.docker.com/examples/running_ssh_service/). Also there are a lot of images in Docker hub with it (as the one in the example tutum/ubuntu:trusty).

Note about exposing SSH port: If your chef workstation (the one with knife configured) is not the one that runs your container, you can expose ssh port to one's of the host machine and then accessing to your HOST_IP to that port. In example:

CONTAINER=$(docker run -d -p 2222:22 -e ROOT_PASS="mypass" tutum/ubuntu:trusty)

knife bootstrap $HOST_IP -p 2222 -x root -P mypass --sudo -r 'role[myrole]'

Upvotes: 5

Related Questions