Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_container fails to :run #1146

Open
urlund opened this issue Dec 2, 2020 · 5 comments
Open

docker_container fails to :run #1146

urlund opened this issue Dec 2, 2020 · 5 comments
Labels
Bug Something isn't working

Comments

@urlund
Copy link
Contributor

urlund commented Dec 2, 2020

πŸ‘» Brief Description

Cannot :run containers.

πŸ₯ž Cookbook version

Version: 7.2.2

πŸ‘©β€πŸ³ Version

Chef: 14.15.6

🎩 Platform details

Fails on a newer docker version (Server Version: 19.03.13 - docker desktop for mac) but it works on an older version (Server Version: 19.03.12 - debian)

I'm running chef in a docker container and mounts the socket as a volume, like this:

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock username/chef-client

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create a simple recipe with the following content:
# ...
docker_image "nginx:latest" do
    repo   "nginx"
    tag    "latest"
    action :pull
end

# ...
docker_image "php:7.4-fpm" do
    repo   "php"
    tag    "7.4-fpm"
    action :pull
end

#...
docker_container "test_nginx" do
    repo    "nginx"
    port    [ "8080:80", "8443:443" ]
end

# ...
docker_container "test_php_1" do
    repo         "php"
    tag          "7.4-fpm"
end

# ...
docker_container "test_php_2" do
    repo         "php"
    tag          "7.4-fpm"
end
  1. Include in run_list

πŸš“ Expected behavior

I get this on an older docker version (running on debian)

Recipe: test::default
  * docker_image[nginx:latest] action pull
    - Pull image nginx:latest
  * docker_image[php:7.4-fpm] action pull
    - Pull image php:7.4-fpm
  * docker_container[test_nginx] action run
    - create test_nginx
    ...
    - starting test_nginx
  * docker_container[test_php_1] action run
    - create test_php_1
    ...
    - starting test_php_1
  * docker_container[test_php_2] action run
    - create test_php_2
    ...
    - starting test_php_2

On a newer version (docker desktop) I get this:

Recipe: test::default
  * docker_image[nginx:latest] action pull
    - Pull image nginx:latest
  * docker_image[php:7.4-fpm] action pull
    - Pull image php:7.4-fpm
  * docker_container[test_nginx] action run

    ================================================================================
    Error executing action `run` on resource 'docker_container[test_nginx]'
    ================================================================================

    Excon::Error::Socket
    --------------------
    no implicit conversion of nil into String (TypeError)

    Cookbook Trace:
    ---------------
    /etc/chef/.cache/cookbooks/docker/libraries/docker_container.rb:408:in `block (2 levels) in <class:DockerContainer>'
    /etc/chef/.cache/cookbooks/docker/libraries/docker_base.rb:29:in `with_retries'
    /etc/chef/.cache/cookbooks/docker/libraries/docker_container.rb:408:in `block in <class:DockerContainer>'

    Resource Declaration:
    ---------------------
    # In /etc/chef/.cache/cookbooks/test/recipes/default.rb

     25: docker_container "test_nginx" do
     26:     repo    "nginx"
     27:     port    [ "8080:80", "8443:443" ]
     28: end
     29:

    Compiled Resource:
    ------------------
    # Declared in /etc/chef/.cache/cookbooks/test/recipes/default.rb:25:in `from_file'

βž• Additional context

I've done some digging and it seems to be an issue with the the response format from the docker socket.

I've previously used the docker cookbook on docker desktop for mac, where everything has been working as expected, thats why I suspect the docker version to be the reason for this issue.

@ramereth
Copy link
Contributor

ramereth commented Dec 2, 2020

@urlund is this only happening on Mac Desktops or does this also happen on Linux desktops using the newer version of Docker?

@ramereth ramereth added the Bug Something isn't working label Dec 2, 2020
@urlund
Copy link
Contributor Author

urlund commented Dec 2, 2020

@ramereth - I just tested Docker version 19.03.14 on Ubuntu 20.04 (in VirtualBox for Mac) - everything seems to work as expected.

@ramereth
Copy link
Contributor

ramereth commented Dec 2, 2020

@urlund what version of the docker-api gem do you have installed? I wonder if you're running into a similar issue we're seeing in test-kitchen/kitchen-dokken#208

@urlund
Copy link
Contributor Author

urlund commented Dec 3, 2020

@ramereth you are right, it's related to the docker-api gem. I modified the docker cookbook to:

gem 'docker-api', '>= 1.34', '< 2' (also modified metadata.json)

And deleted the docker-api-2.0.0 from the gems folder. And now i get this on docker desktop:

Recipe: test::default
  * docker_image[nginx:latest] action pull (up to date)
  * docker_image[php:7.4-fpm] action pull (up to date)
  * docker_container[test_nginx] action run
    - create test_nginx
    ...
    - starting test_nginx
  * docker_container[test_php_1] action run
    - create test_php_1
    ...
    - starting test_php_1
  * docker_container[test_php_2] action run
    - create test_php_2
    ...
    - starting test_php_2

@ramereth
Copy link
Contributor

ramereth commented Dec 3, 2020

We'll need to look more closely at what needs to be fixed on our end. Feel free to make a PR if you figure out it and we'll get it reviewed/merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants