user3270211
user3270211

Reputation: 933

Running docker run in Chef

I am looking to make Chef manage running docker containers. However I am not sure how to move forward. This the docker run command which I use today and want to make it Chef friendly and move it into my recipies:

docker run --name=nginx--restart=unless-stopped -p 443:443 -p 80:80 --privileged=true -v /etc/php:/conf/stack -v /var/www/html -d repository.com/nginx:v1.5.3

Any tips or ideas?

Upvotes: 1

Views: 1466

Answers (1)

Belogix
Belogix

Reputation: 8147

You can use the "official" Docker cookbook from Chef's Supermarket - https://supermarket.chef.io/cookbooks/docker

Then as an example you can do:

# Pull latest image
docker_image 'nginx' do
  tag 'latest'
  action :pull
  notifies :redeploy, 'docker_container[my_nginx]'
end

# Run container mapping containers port 80 to the host's port 80
docker_container 'my_nginx' do
  repo 'nginx'
  tag 'latest'
  port '80:80'
  host_name 'www'
  domain_name 'computers.biz'
  env 'FOO=bar'
  volumes [ '/some/local/files/:/etc/nginx/conf.d' ]
end

Upvotes: 1

Related Questions