Giter Site home page Giter Site logo

puppetlabs-docker's Introduction

Puppet Forge Puppet Forge Downloads Puppet Forge Endorsement

Docker

Table of Contents

  1. Description
  2. Setup
  3. Usage - Configuration options and additional functionality
  4. Reference - An under-the-hood peek at what the module is doing and how
  5. Limitations - OS compatibility, etc.
  6. License
  7. Development - Guide for contributing to the module
  8. Acceptance

Description

The Puppet docker module installs, configures, and manages Docker from the Docker repository. It supports the latest Docker CE (Community Edition) for Linux based distributions and Docker EE(Enterprise Edition) for Windows and Linux as well as legacy releases.

Due to the new naming convention for Docker packages, this module prefaces any params that refer to the release with _ce or _engine. Examples of these are documented in this README.

Setup

To create the Docker hosted repository and install the Docker package, add a single class to the manifest file:

include 'docker'

To configure package sources independently and disable automatically including sources, add the following code to the manifest file:

class { 'docker':
  use_upstream_package_source => false,
}

The latest Docker repositories are now the default repositories for version 17.06 and above. If you are using an older version, the repositories are still configured based on the version number passed into the module.

To ensure the module configures the latest repositories, add the following code to the manifest file:

class { 'docker':
  version => '17.09.0~ce-0~debian',
}

Using a version prior to 17.06, configures and installs from the old repositories:

class { 'docker':
  version => '1.12.0-0~wheezy',
}

Docker provides a enterprise addition of the Docker Engine, called Docker EE. To install Docker EE on Debian systems, add the following code to the manifest file:

class { 'docker':
  docker_ee                 => true,
  docker_ee_source_location => 'https://<docker_ee_repo_url>',
  docker_ee_key_source      => 'https://<docker_ee_key_source_url>',
  docker_ee_key_id          => '<key id>',
}

To install Docker EE on RHEL/CentOS:

class { 'docker':
  docker_ee                 => true,
  docker_ee_source_location => 'https://<docker_ee_repo_url>',
  docker_ee_key_source      => 'https://<docker_ee_key_source_url>',
}

For CentOS distributions, the docker module requires packages from the extras repository, which is enabled by default on CentOS. For more information, see the official CentOS documentation and the official Docker documentation.

For Red Hat Enterprise Linux (RHEL) based distributions, the docker module uses the upstream repositories. To continue using the legacy distribution packages in the CentOS extras repository, add the following code to the manifest file:

class { 'docker':
  use_upstream_package_source => false,
  service_overrides_template  => false,
  docker_ce_package_name      => 'docker',
}

To use the CE packages, add the following code to the manifest file:

class { 'docker':
  use_upstream_package_source => false,
  repo_opt                    => '',
}

By default, the Docker daemon binds to a unix socket at /var/run/docker.sock. To change this parameter and update the binding parameter to a tcp socket, add the following code to the manifest file:

class { 'docker':
  tcp_bind    => ['tcp://127.0.0.1:2375'],
  socket_bind => 'unix:///var/run/docker.sock',
  ip_forward  => true,
  iptables    => true,
  ip_masq     => true,
  bip         => '192.168.1.1/24',
  fixed_cidr  => '192.168.1.144/28',
}

For more information about the configuration options for the default docker bridge, see the Docker documentation.

The default group ownership of the Unix control socket differs based on OS. For example, on RHEL using docker-ce packages >=18.09.1, the socket file used by /usr/lib/systemd/system/docker.socket is owned by the docker group. To override this value in /etc/sysconfig/docker and docker.socket (e.g. to use the 'root' group):

class {'docker':
  socket_group    => 'root',
  socket_override => true,
}

The socket_group parameter also takes a boolean for legacy cases where setting -G in /etc/sysconfig/docker is not desired:

docker::socket_group: false

To add another service to the After= line in the [Unit] section of the systemd /etc/systemd/system/service-overrides.conf file, use the service_after_override parameter:

docker::service_after_override: containerd.service

When setting up TLS, upload the related files (CA certificate, server certificate, and key) and include their paths in the manifest file:

class { 'docker':
  tcp_bind   => ['tcp://0.0.0.0:2376'],
  tls_enable => true,
  tls_cacert => '/etc/docker/tls/ca.pem',
  tls_cert   => '/etc/docker/tls/cert.pem',
  tls_key    => '/etc/docker/tls/key.pem',
}

To specify which Docker rpm package to install, add the following code to the manifest file:

class { 'docker':
  manage_package              => true,
  use_upstream_package_source => false,
  package_engine_name         => 'docker-engine'
  package_source_location     => 'https://get.docker.com/rpm/1.7.0/centos-6/RPMS/x86_64/docker-engine-1.7.0-1.el6.x86_64.rpm',
  prerequired_packages        => [ 'glibc.i686', 'glibc.x86_64', 'sqlite.i686', 'sqlite.x86_64', 'device-mapper', 'device-mapper-libs', 'device-mapper-event-libs', 'device-mapper-event' ]
}

To track the latest version of Docker, add the following code to the manifest file:

class { 'docker':
  version => latest,
}

To install docker from a test or edge channel, add the following code to the manifest file:

class { 'docker':
  docker_ce_channel => 'test'
}

To allocate a DNS server to the Docker daemon, add the following code to the manifest file:

class { 'docker':
  dns => '8.8.8.8',
}

To add users to the Docker group, add the following array to the manifest file:

class { 'docker':
  docker_users => ['user1', 'user2'],
}

To add daemon labels, add the following array to the manifest file:

class { 'docker':
  labels => ['storage=ssd','stage=production'],
}

To pass additional parameters to the daemon, add extra_parameters to the manifest file:

class { 'docker':
  extra_parameters => ['--experimental=true', '--metrics-addr=localhost:9323'],

To uninstall docker, add the following to the manifest file:

class { 'docker':
  ensure => absent
}

Only Docker EE is supported on Windows. To install docker on Windows 2016 and above, the docker_ee parameter must be specified:

class { 'docker':
  docker_ee => true
}

If the curl package is being managed elsewhere and the curl ensure in this module is conflicting, it can be disabled by setting the following parameter globally or in compose / machine resources:

class { 'docker':
  curl_ensure => false
}

Proxy on Windows

To use docker through a proxy on Windows, a System Environment Variable HTTP_PROXY/HTTPS_PROXY must be set. See Docker Engine on Windows This can be done using a different puppet module, such as the puppet-windows_env module. After setting the variable, the docker service must be restarted.

windows_env { 'HTTP_PROXY'
  value  => 'http://1.2.3.4:80',
  notify => Service['docker'],
}
windows_env { 'HTTPS_PROXY'
  value  => 'http://1.2.3.4:80',
  notify => Service['docker'],
}
service { 'docker'
  ensure => 'running',
}

Validating and unit testing the module

This module is compliant with the Puppet Development Kit (PDK), which provides tools to help run unit tests on the module and validate the modules' metadata, syntax, and style.

To run all validations against this module, run the following command:

pdk validate

To change validation behavior, add options flags to the command. For a complete list of command options and usage information, see the PDK command reference.

To unit test the module, run the following command:

pdk test unit

To change unit test behavior, add option flags to the command. For a complete list of command options and usage information, see the PDK command reference.

Usage

Images

Each image requires a unique name; otherwise, the installation fails when a duplicate name is detected.

To install a Docker image, add the docker::image defined type to the manifest file:

docker::image { 'base': }

The code above is equivalent to running the docker pull base command. However, it removes the default five-minute execution timeout.

To include an optional parameter for installing image tags that is the equivalent to running docker pull -t="precise" ubuntu, add the following code to the manifest file:

docker::image { 'ubuntu':
  image_tag => 'precise'
}

Including the docker_file parameter is equivalent to running the docker build -t ubuntu - < /tmp/Dockerfile command. To add or build an image from a dockerfile that includes the docker_file parameter, add the following code to the manifest file:

docker::image { 'ubuntu':
  docker_file => '/tmp/Dockerfile'
}

Including the docker_dir parameter is equivalent to running the docker build -t ubuntu /tmp/ubuntu_image command. To add or build an image from a dockerfile that includes the docker_dir parameter, add the following code to the manifest file:

docker::image { 'ubuntu':
  docker_dir => '/tmp/ubuntu_image'
}

To rebuild an image, subscribe to external events such as Dockerfile changes by adding the following code to the manifest file:

docker::image { 'ubuntu':
  docker_file => '/tmp/Dockerfile',
  subscribe   => File['/tmp/Dockerfile'],
}

file { '/tmp/Dockerfile':
  ensure => file,
  source => 'puppet:///modules/someModule/Dockerfile',
}

To remove an image, add the following code to the manifest file:

docker::image { 'base':
  ensure => 'absent'
}

docker::image { 'ubuntu':
  ensure    => 'absent',
  image_tag => 'precise'
}

To configure the docker::images class when using Hiera, add the following code to the manifest file:

---
  classes:
    - docker::images

docker::images::images:
  ubuntu:
    image_tag: 'precise'

Containers

To launch containers, add the following code to the manifest file:

docker::run { 'helloworld':
  image   => 'base',
  command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
}

This is equivalent to running the docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done" command to launch a Docker container managed by the local init system.

run includes a number of optional parameters:

docker::run { 'helloworld':
  image            => 'base',
  detach           => true,
  service_prefix   => 'docker-',
  command          => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
  ports            => ['4444', '4555'],
  expose           => ['4666', '4777'],
  links            => ['mysql:db'],
  net              => ['my-user-def-net','my-user-def-net-2'],
  disable_network  => false,
  volumes          => ['/var/lib/couchdb', '/var/log'],
  volumes_from     => '6446ea52fbc9',
  memory_limit     => '10m', # (format: '<number><unit>', where unit = b, k, m or g)
  cpuset           => ['0', '3'],
  username         => 'example',
  hostname         => 'example.com',
  env              => ['FOO=BAR', 'FOO2=BAR2'],
  env_file         => ['/etc/foo', '/etc/bar'],
  labels           => ['com.example.foo="true"', 'com.example.bar="false"'],
  dns              => ['8.8.8.8', '8.8.4.4'],
  restart_service  => true,
  privileged       => false,
  pull_on_start    => false,
  before_stop      => 'echo "So Long, and Thanks for All the Fish"',
  before_start     => 'echo "Run this on the host before starting the Docker container"',
  after_stop       => 'echo "container has stopped"',
  after_start      => 'echo "container has started"',
  after            => [ 'container_b', 'mysql' ],
  depends          => [ 'container_a', 'postgres' ],
  stop_wait_time   => 10,
  read_only        => false,
  extra_parameters => [ '--restart=always' ],
}

You can specify the ports, expose, env, dns, and volumes values with a single string or an array.

To pull the image before it starts, specify the pull_on_start parameter.

Use the detach param to run a container without the -a flag. This is only required on systems without systemd. This default is set in the params.pp based on the OS. Only override if you understand the consequences and have a specific use case.

To execute a command before the container starts or stops, specify the before_start or before_stop parameters, respectively. Similarly, you can set the after_start or after_stop parameters to run a command after the container starts or stops.

Adding the container name to the after parameter to specify which containers start first affects the generation of the init.d/systemd script.

Add container dependencies to the depends parameter. The container starts before this container and stops before the dependent container. This affects the generation of the init.d/systemd script. Use the depend_services parameter to specify dependencies for general services, which are not Docker related, that start before this container.

The extra_parameters parameter, which contains an array of command line arguments to pass to the docker run command, is useful for adding additional or experimental options that the docker module currently does not support.

By default, automatic restarting of the service on failure is enabled by the service file for systemd based systems.

It's recommended that an image tag is used at all times with the docker::run define type. If not, the latest image is used whether it's in a remote registry or installed on the server already by the docker::image define type.

NOTE: As of v3.0.0, if the latest tag is used the image will be the latest at the time the of the initial puppet run. Any subsequent puppet runs will always reference the latest local image. Therefore, it's recommended that an alternative tag be used, or the image be removed before pulling latest again.

To use an image tag, add the following code to the manifest file:

docker::run { 'helloworld':
  image   => 'ubuntu:precise',
  command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
}

By default, when the service stops or starts, the generated init scripts remove the container, but not the associated volumes. To change this behaviour, add the following code to the manifest file:

docker::run { 'helloworld':
  remove_container_on_start => true,
  remove_volume_on_start    => false,
  remove_container_on_stop  => true,
  remove_volume_on_stop     => false,
}

If using Hiera, you can configure the docker::run_instance class:

---
  classes:
    - docker::run_instance

  docker::run_instance::instance:
    helloworld:
      image: 'ubuntu:precise'
      command: '/bin/sh -c "while true; do echo hello world; sleep 1; done"'

To remove a running container, add the following code to the manifest file. This also removes the systemd service file associated with the container.

docker::run { 'helloworld':
  ensure => absent,
}

To enable the restart of an unhealthy container, add the following code to the manifest file. To set the health check interval time, set the optional health_check_interval parameter. The default health check interval is 30 seconds.

docker::run { 'helloworld':
  image                 => 'base',
  command               => 'command',
  health_check_cmd      => '<command_to_execute_to_check_your_containers_health>',
  restart_on_unhealthy  => true,
  health_check_interval => '<time between running docker healthcheck>',

To run command on Windows 2016 requires the restart parameter to be set:

docker::run { 'helloworld':
  image   => 'microsoft/nanoserver',
  command => 'ping 127.0.0.1 -t',
  restart => 'always'

Networks

Docker 1.9.x supports networks. To expose the docker_network type that is used to manage networks, add the following code to the manifest file:

docker_network { 'my-net':
  ensure   => present,
  driver   => 'overlay',
  subnet   => '192.168.1.0/24',
  gateway  => '192.168.1.1',
  ip_range => '192.168.1.4/32',
}

The name value and the ensure parameter are required. If you do not include the driver value, the default bridge is used. The Docker daemon must be configured for some networks, and configuring the cluster store for the overlay network would be an example.

To configure the cluster store, update the docker class in the manifest file:

extra_parameters => '--cluster-store=<backend>://172.17.8.101:<port> --cluster-advertise=<interface>:2376'

If using Hiera, configure the docker::networks class in the manifest file:

---
  classes:
    - docker::networks

docker::networks::networks:
  local-docker:
    ensure: 'present'
    subnet: '192.168.1.0/24'
    gateway: '192.168.1.1'

A defined network can be used on a docker::run resource with the net parameter.

Windows

On Windows, only one NAT network is supported. To support multiple networks, Windows Server 2016 with KB4015217 is required. See Windows Container Network Drivers and Windows Container Networking.

The Docker daemon will create a default NAT network on the first start unless specified otherwise. To disable the network creation, use the parameter bridge => 'none' when installing docker.

Volumes

Docker 1.9.x added support for volumes. These are NOT to be confused with the legacy volumes, now known as bind mounts. To expose the docker_volume type, which is used to manage volumes, add the following code to the manifest file:

docker_volume { 'my-volume':
  ensure => present,
}

You can pass additional mount options to the local driver. For mounting an NFS export, use:

docker_volume { 'nfs-volume':
  ensure  => present,
  driver  => 'local',
  options => ['type=nfs','o=addr=%{custom_manager},rw','device=:/srv/blueocean']
}

The name value and the ensure parameter are required. If you do not include the driver value, the default local is used.

If using Hiera, configure the docker::volumes class in the manifest file:

---
  classes:
    - docker::volumes

docker::volumes::volumes:
  blueocean:
    ensure: present
    driver: local
    options:
      - ['type=nfs','o=addr=%{custom_manager},rw','device=:/srv/blueocean']

Available parameters for options depend on the used volume driver. For details, see Using volumes from the Docker manual.

Some of the key advantages for using volumes over bind mounts are:

  • Easier to back up or migrate rather than bind mounts (legacy volumes).
  • Managed with Docker CLI or API (Puppet type uses the CLI commands).
  • Works on Windows and Linux.
  • Easily shared between containers.
  • Allows for store volumes on remote hosts or cloud providers.
  • Encrypt contents of volumes.
  • Add other functionality
  • New volume's contents can be pre-populated by a container.

When using the volumes array with docker::run, the command on the backend will know if it needs to use bind mounts or volumes based on the data passed to the -v option.

Running docker::run with native volumes:

docker::run { 'helloworld':
  image   => 'ubuntu:precise',
  command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
  volumes => ['my-volume:/var/log'],
}

Compose

Docker Compose describes a set of containers in YAML format and runs a command to build and run those containers. Included in the docker module is the docker_compose type. This enables Puppet to run Compose and remediate any issues to ensure reality matches the model in your Compose file.

Before you use the docker_compose type, you must install the Docker Compose utility.

To install Docker Compose, add the following code to the manifest file:

class {'docker::compose':
  ensure  => present,
  version => '1.9.0',
}

Set the version parameter to any version you need to install.

This is an example of a Compose file:

compose_test:
  image: ubuntu:14.04
  command: /bin/sh -c "while true; do echo hello world; sleep 1; done"

Specify the file resource to add a Compose file to the machine you have Puppet running on. To define a docker_compose resource pointing to the Compose file, add the following code to the manifest file:

docker_compose { 'test':
  compose_files => ['/tmp/docker-compose.yml'],
  ensure        => present,
}

Puppet automatically runs Compose because the relevant Compose services aren't running. If required, include additional options such as enabling experimental features and scaling rules.

Additionally, the TMPDIR environment variable can optionally be set when docker_compose runs if you want Puppet to manage the environment variable within the scope of the resource. This is effective when noexec is set on the default /tmp dir, however you must ensure that the target directory exists as the resource will not create it.

In the example below, Puppet runs Compose when the number of containers specified for a service doesn't match the scale values. The optional tmpdir parameter is also specified.

docker_compose { 'test':
  compose_files => ['/tmp/docker-compose.yml'],
  ensure        => present,
  scale         => {
    'compose_test' => 2,
  },
  tmpdir        => '/usr/local/share/tmp_docker',
  options       => ['--x-networking']
}

Give options to the docker-compose up command, such as --remove-orphans, by using the up_args option.

To supply multiple overide compose files add the following to the manifest file:

docker_compose {'test':
  compose_files => ['server-docker-compose.yml', 'override-compose.yml'],
}

Please note you should supply your server docker-compose file as the first element in the array. As per docker, multi compose file support compose files are merged in the order they are specified in the array.

If you are using a v3.2 compose file or above on a Docker Swarm cluster, use the docker::stack class. Include the file resource before you run the stack command.

NOTE: this define will be deprecated in a future release in favor of the docker stack type

To deploy the stack, add the following code to the manifest file:

 docker::stack { 'yourapp':
   ensure        => present,
   stack_name    => 'yourapp',
   compose_files => ['/tmp/docker-compose.yaml'],
   require       => [Class['docker'], File['/tmp/docker-compose.yaml']],
}

To remove the stack, set ensure => absent.

If you are using a v3.2 compose file or above on a Docker Swarm cluster, include the docker::stack class. Similar to using older versions of Docker, compose the file resource before running the stack command.

To deploy the stack, add the following code to the manifest file.

docker::stack { 'yourapp':
  ensure             => present,
  stack_name         => 'yourapp',
  compose_files      => ['/tmp/docker-compose.yaml'],
  with_registry_auth => true,
  require            => [Class['docker'], File['/tmp/docker-compose.yaml']],
}

To use the equivalent type and provider, use the following in your manifest file. For more information on specific parameters see the docker_stack type documentation.

docker_stack { 'test':
  compose_files => ['/tmp/docker-compose.yml'],
  ensure        => present,
  up_args       => '--with-registry-auth',
}

To remove the stack, set ensure => absent.

Machine

You can use Docker Machine to install Docker Engine on virtual hosts and manage the hosts with docker-machine commands. You can also use Machine to create Docker hosts on your local Mac or Windows box, on your company network, in your data center, or on cloud providers like Azure, AWS, or Digital Ocean.

For more information on machines, see the Docker Machines documentation.

This module only installs the Docker Machine utility.

To install Docker Machine, add the following code to the manifest file:

class {'docker::machine':
  ensure  => present,
  version => '1.16.1',
}

Set the version parameter to any version you need to install.

Swarm mode

To natively manage a cluster of Docker Engines known as a swarm, Docker Engine 1.12 includes a swarm mode.

To cluster your Docker engines, use one of the following Puppet resources:

Windows

To configure swarm, Windows Server 2016 requires KB4015217 and the following firewall ports to be open on all nodes:

  • TCP port 2377 for cluster management communications
  • TCP and UDP port 7946 for communication among nodes
  • UDP port 4789 for overlay network traffic

Swarm manager

To configure the swarm manager, add the following code to the manifest file:

docker::swarm {'cluster_manager':
  init           => true,
  advertise_addr => '192.168.1.1',
  listen_addr    => '192.168.1.1',
}

For a multihomed server and to enable cluster communications between the node, include the advertise_addr and listen_addr parameters.

Swarm worker

To configure the swarm worker, add the following code to the manifest file:

docker::swarm {'cluster_worker':
  join           => true,
  advertise_addr => '192.168.1.2',
  listen_addr    => '192.168.1.2',
  manager_ip     => '192.168.1.1',
  token          => 'your_join_token'
}

To configure a worker node or a second manager, include the swarm manager IP address in the manager_ip parameter. To define the role of the node in the cluster, provide the token parameter. When creating an additional swarm manager and a worker node, separate tokens are required. These tokens (i.e. docker_worker_join_token and docker_manager_join_token) can be retrieved from Facter.

To remove a node from a cluster, add the following code to the manifest file:

docker::swarm {'cluster_worker':
  ensure => absent
}

Tasks

The docker module has an example task that allows a user to initialize, join and leave a swarm.

bolt task run docker::swarm_init listen_addr=172.17.10.101 adverstise_addr=172.17.10.101 ---nodes swarm-master --user <user> --password <password> --modulepath <module_path>

docker swarm init --advertise-addr=172.17.10.101 --listen-addr=172.17.10.101
Swarm initialized: current node (w8syk0g286vd7d9kwzt7jl44z) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-317gw63odq6w1foaw0xkibzqy34lga55aa5nbjlqekcrhg8utl-08vrg0913zken8h9vfo4t6k0t 172.17.10.101:2377

To add a manager to this swarm, run docker swarm join-token manager and follow the instructions.

Ran on 1 node in 4.04 seconds
bolt task run docker::swarm_token node_role=worker ---nodes swarm-master --user <user> --password <password> --modulepath <module_path>

SWMTKN-1-317gw63odq6w1foaw0xkibzqy34lga55aa5nbjlqekcrhg8utl-08vrg0913zken8h9vfo4t6k0t

Ran on 1 node in 4.02 seconds
bolt task run docker::swarm_join listen_addr=172.17.10.102 adverstise_addr=172.17.10.102 token=<swarm_token> manager_ip=172.17.10.101:2377 --nodes swarm-02 --user root --password puppet --modulepath /tmp/modules

This node joined a swarm as a worker.

Ran on 1 node in 4.68 seconds
bolt task run docker::swarm_leave --nodes swarm-02 --user root --password puppet --modulepath --modulepath <module_path>

Node left the swarm.

Ran on 1 node in 6.16 seconds

Docker services

Docker services create distributed applications across multiple swarm nodes. Each Docker service replicates a set of containers across the swarm.

To create a Docker service, add the following code to the manifest file:

docker::services {'redis':
    create       => true,
    service_name => 'redis',
    image        => 'redis:latest',
    publish      => '6379:639',
    replicas     => '5',
    mounts       => ['type=bind,source=/etc/my-redis.conf,target=/etc/redis/redis.conf,readonly'],
    extra_params => ['--update-delay 1m', '--restart-window 30s'],
    command      => ['redis-server', '--appendonly', 'yes'],
  }

To base the service off an image, include the image parameter and set the publish parameter to expose the service port (use an array to specify multiple published ports). To set the number of containers running in the service, include the replicas parameter. To attach one or multiple filesystems to the service, use the mounts parameter. For information regarding the extra_params parameter, see docker service create --help. The command parameter can either be specified as an array or a string.

To update the service, add the following code to the manifest file:

docker::services {'redis_update':
  create       => false,
  update       => true,
  service_name => 'redis',
  replicas     => '3',
}

To update a service without creating a new one, include the the update => true and create => false parameters.

To scale a service, add the following code to the manifest file:

docker::services {'redis_scale':
  create       => false,
  scale        => true,
  service_name => 'redis',
  replicas     => '10',
}

To scale the service without creating a new one, provide the scale => true parameter and the create => false parameters. In the example above, the service is scaled to 10.

To remove a service, add the following code to the manifest file:

docker::services {'redis':
  create       => false,
  ensure       => 'absent',
  service_name => 'redis',
}

To remove the service from a swarm, include the ensure => absent parameter and the service_name parameter.

Private registries

When a server is not specified, images are pushed and pulled from index.docker.io. To qualify your image name, create a private repository without authentication.

To configure authentication for a private registry, add the following code to the manifest file, depending on what version of Docker you are running. If you are using Docker V1.10 or earlier, specify the docker version in the manifest file:

docker::registry { 'example.docker.io:5000':
  username => 'user',
  password => 'secret',
  email    => '[email protected]',
  version  => '<docker_version>'
}

To pull images from the docker store, use the following as the registry definition with your docker hub credentials.

  docker::registry {'https://index.docker.io/v1/':
    username => 'username',
    password => 'password',
  }

If using hiera, configure the docker::registry_auth class:

docker::registry_auth::registries:
  'example.docker.io:5000':
    username: 'user1'
    password: 'secret'
    email: '[email protected]'
    version: '<docker_version>'

If using Docker V1.11 or later, the docker login email flag has been deprecated. See the docker_change_log.

Add the following code to the manifest file:

docker::registry { 'example.docker.io:5000':
  username => 'user',
  password => 'secret',
}

If using hiera, configure the 'docker::registry_auth' class:

docker::registry_auth::registries:
  'example.docker.io:5000':
    username: 'user1'
    password: 'secret'

To log out of a registry, add the following code to the manifest file:

docker::registry { 'example.docker.io:5000':
  ensure => 'absent',
}

To set a preferred registry mirror, add the following code to the manifest file:

class { 'docker':
  registry_mirror => 'http://testmirror.io'
}

Exec

Within the context of a running container, the docker module supports arbitrary commands:

docker::exec { 'cron_allow_root':
  detach      => true,
  container   => 'mycontainer',
  command     => '/bin/echo root >> /usr/lib/cron/cron.allow',
  onlyif      => 'running',
  tty         => true,
  env         => ['FOO=BAR', 'FOO2=BAR2'],
  unless      => 'grep root /usr/lib/cron/cron.allow 2>/dev/null',
  refreshonly => true,
}

Plugin

The module supports the installation of Docker plugins:

docker::plugin {'foo/fooplugin:latest':
  settings => ['VAR1=test','VAR2=value']
}

To disable an active plugin:

docker::plugin {'foo/fooplugin:latest':
  enabled => false,
}

To remove an active plugin:

docker::plugin {'foo/fooplugin:latest'
  ensure => 'absent',
  force_remove => true,
}

Reference

For information on classes, types, and functions, see the REFERENCE.md.

Limitations

This module supports:

  • Centos 7.0
  • Debian 8.0
  • Debian 9.0
  • Debian 10
  • Debian 11
  • RedHat 7.0 - limited support available
  • Ubuntu 18.04
  • Ubuntu 20.04
  • Ubuntu 22.04
  • Windows Server 2016 (Docker Enterprise Edition only)
  • Windows Server 2019 (Docker Enterprise Edition only)
  • Windows Server 2022 (Docker Enterprise Edition only)

On RedHat 7 the default docker package installs docker server version 1.13.1. The default docker.service uses the docker-storage-service in this version and creates /etc/sysconfig/docker-storage based on the container-storage-setup configuration and /etc/sysconfig/docker-storage-setup file. As the puppetlabs-docker module manages both the docker-storage and docker-storage-setup files it causes a conflict with the container-storage-setup forcing a docker service restart, therefore a workaround was included in the service manifest that disables the service restart on storage configuration changes for this version of docker on RedHat 7. As a side effect of these changes, storage configuration changes with this docker version on RedHat 7 are not picked up by default by the docker.service.

License

This codebase is licensed under the Apache2.0 licensing, however due to the nature of the codebase the open source dependencies may also use a combination of AGPL, BSD-2, BSD-3, GPL2.0, LGPL, MIT and MPL Licensing.

Development

If you would like to contribute to this module, see the guidelines in CONTRIBUTING.MD.

Acceptance

Acceptance tests for this module leverage puppet_litmus. To run the acceptance tests follow the instructions here.

puppetlabs-docker's People

Contributors

adrianiurca avatar canihavethisone avatar chelnak avatar daianamezdrea avatar davejrt avatar david22swan avatar davids avatar eimlav avatar electrofelix avatar esalberg avatar florindragos avatar gregohardy avatar gspatton avatar jacksgt avatar jordanbreen28 avatar khaefeli avatar lionce avatar lukasaud avatar malikparvez avatar michaeltlombardi avatar mihaibuzgau avatar pmcmaw avatar ramesh7 avatar rbelnap avatar rxm307 avatar sanfrancrisko avatar scotty-c avatar sheenaajay avatar smortex avatar tmanninger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppetlabs-docker's Issues

docker::registry: Allow password to be provided as a hash

pw_hash has issues with FIPS systems (MODULES-6135), so I would like to be able to provide a password as a hash to skip the pw_hash function.

The line https://github.com/puppetlabs/puppetlabs-docker/blob/master/manifests/registry.pp#L71, which specifies SHA-512, still fails on pw_hash (weird).

My test environment can be replicated by cloning simp/simp_docker, installing the gems etc, and running BEAKER_fips=yes BEAKER_destroy=no rake 'beaker:suites[redhat]'. It should fail on this line: https://github.com/simp/pupmod-simp-simp_docker/blob/master/spec/acceptance/suites/redhat/30_registry_spec.rb#L81

Clean up deprecations

I get various warnings about deprecations when using the docker module.

$ puppet --version
4.10.8

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS"
$ cat manifests/docker.pp 
class { 'docker':
  docker_users => ['vagrant'],
}

$ sudo /opt/puppetlabs/bin/puppet apply manifests/docker.pp
Warning: /etc/puppetlabs/puppet/hiera.yaml: Use of 'hiera.yaml' version 3 is deprecated. It should be converted to version 5
   (in /etc/puppetlabs/puppet/hiera.yaml)
Warning: This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README. at ["/etc/puppetlabs/code/environments/production/modules/docker/manifests/init.pp", 445]:
   (at /etc/puppetlabs/code/environments/production/modules/stdlib/lib/puppet/functions/deprecation.rb:25:in `deprecation')
Warning: This method is deprecated, please use the stdlib validate_legacy function, with Pattern[]. There is further documentation for validate_legacy function in the README. at ["/etc/puppetlabs/code/environments/production/modules/docker/manifests/init.pp", 446]:
   (at /etc/puppetlabs/code/environments/production/modules/stdlib/lib/puppet/functions/deprecation.rb:25:in `deprecation')
Warning: This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README. at ["/etc/puppetlabs/code/environments/production/modules/docker/manifests/init.pp", 448]:
   (at /etc/puppetlabs/code/environments/production/modules/stdlib/lib/puppet/functions/deprecation.rb:25:in `deprecation')
Warning: This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README. at ["/etc/puppetlabs/code/environments/production/modules/docker/manifests/init.pp", 452]:
   (at /etc/puppetlabs/code/environments/production/modules/stdlib/lib/puppet/functions/deprecation.rb:25:in `deprecation')
Warning: This method is deprecated, please use match expressions with Stdlib::Compat::Array instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions. at ["/etc/puppetlabs/code/environments/production/modules/apt/manifests/pin.pp", 43]:
   (at /etc/puppetlabs/code/environments/production/modules/stdlib/lib/puppet/functions/deprecation.rb:25:in `deprecation')
Notice: Compiled catalog for ubuntu-xenial.localdomain in environment production in 0.71 seconds
Notice: Applied catalog in 0.41 seconds```

Cannot install

Hello! Just started trying to make this work and I'm getting an error that I can't seem to decode.

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Could not find template 'docker/etc/systemd/system/docker.service.d/service-overrides-debian.conf.erb' at /etc/puppetlabs/code/environments/production/modules/docker/manifests/service.pp:160:22 on node dock1
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

Sort of a specific error so Google was no help. Any idea what this may be?

I'm on Ubuntu 16.04 LTS, fresh install and up to date.

Here's the code I'm using:

	# Docker
	class { 'docker':
  		tcp_bind        => ['tcp://0.0.0.0:2375'],
  		socket_bind     => 'unix:///var/run/docker.sock'
	}

Thank you and please let me know if you have any ideas!

No IPv6 support

The Docker class doesn't support the IPv6-options to dockerd, such as --ipv6, --fixed-cidr-v6 and --default-gateway-v6 . Fortunately the extra_parameters option provides a workaround. It would be nicer to configure IPv6 in the same place as IPv4. As fixed_cidr and default_gateway are supported I think the IPv6 equivalents should be added as well.

docker-engine install not working on RHEL 7

Hey Guys,

We're seeing an issue with this mod (we think) after issue #31 was merged in. We're running RHEL 7.4 and unfortunately docker-engine 1.12.6. The issue that just started occurring is with installing docker. Below is our puppet code (note that we recently switched to this mod from garethr/docker):

  class { 'docker':
    docker_users               => ['ouruser'],
    repo_opt                   => '',
    version                    => $version,
    service_overrides_template => false, # Required as Docker module breaks default rhel Docker installation.
    service_config             => false, # Required as Docker module breaks default rhel Docker installation.
    storage_config             => false, # Required as Docker module breaks default rhel Docker installation.
  }

With version 1.0.2 of this mod we see the following in our puppet reports:

baseurl changed 'https://yum.dockerproject.org/repo/main/centos/7' to 'https://yum.dockerproject.org/repo/main/redhat/7'
Source:	/Stage[main]/Docker::Repos/Yumrepo[docker]/baseurlFile:	/etc/puppetlabs/code/environments/production/modules/docker/manifests/repos.ppLine:	60

The old module was setting the baseurl in /etc/yum.repos.d/docker.repo to https://yum.dockerproject.org/repo/main/centos/7, which contains the docker-engine rpm at version 1.12.6. The update to the mod is setting the baseurl in docker.repo to: https://yum.dockerproject.org/repo/main/redhat/7. We do have valid RHEL licenses and our machines are subscribed to Redhat via the subscription manager.

In order to resolve our issue we have reverted the module back to version 1.0.1

Seems this line of code is where the baseurl for the repo is being set:

$package_ce_source_location = "https://download.docker.com/linux/${os}/${::operatingsystemmajrelease}/${::architecture}/${docker_ce_channel}"

Thanks!

Docker module shouldn't manage the EPEL repository (via the epel module)

This is specifically an issue on RHEL/CentOS < 7 (Specifically, this code )

Use cases:

  1. A user uses another module to manage the EPEL repository that conflicts with the module that puppetlabs-docker requires. (As discussed in this thread, where the developer states "have whatever is requiring a specific epel module to stop that."
  2. A user uses yumrepo to manage EPEL rather than a module (which is what we do because we have a local copy of all the repositories we use)

Possible fix:

Add a class variable such as 'manage_epel' that can be set to false for users where EPEL is already being managed though some other means.

$service_name not correctly setting sysconfig locations

Somewhat Related to Issue #43

If you use docker-latest package
ie.

class { 'docker':
    package_name			=> 'docker-latest',
    service_name			=> 'docker-latest',
}

This does not set $service_config correctly as this is hardcoded in params.pp depending on which distro your running
ie.

      $service_config = "/etc/sysconfig/docker"
      $storage_config = "/etc/sysconfig/docker-storage"
      $storage_setup_file = "/etc/sysconfig/docker-storage-setup"

Should this logic be moved from params.pp to service.pp and set as variables?
ie.

      $service_config = "/etc/sysconfig/${service_name}"
      $storage_config = "/etc/sysconfig/${service_name}-storage"
      $storage_setup_file = "/etc/sysconfig/${service_name}-storage-setup"

or is it acceptable that you need to declare this?
ie.

class { 'docker':
	use_upstream_package_source 	=> false,
	docker_command			=> 'docker-latest',
	package_name			=> 'docker-latest',
	service_name			=> 'docker-latest',
	service_config			=> '/etc/sysconfig/docker-latest',
	storage_config			=> '/etc/sysconfig/docker-latest-storage',
	storage_setup_file		=> '/etc/sysconfig/docker-latest-storage-setup',
}

Pdk update

This module was created before the release of the PDK, are there any plans for moving this to using the PDK?

unable to remove docker services

as per the README I tried adding
docker::services {'filebeat':
ensure => 'absent',
service_name => 'filebeat',
}

but as it defaults to create = true in services.pp so I tried create => false but it still tries to create

docker::services {'filebeat':
  create => false,
  ensure => 'absent',
  service_name => 'filebeat',
}

Exec[Docker service create]/returns: "docker service create" requires at least 1 argument(s).
Exec[Docker service create]/returns: See 'docker service create --help'.
Exec[Docker service create]/returns:
Exec[Docker service create]/returns: Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG...]
Exec[Docker service create]/returns:
Exec[Docker service create]/returns: Create a new service
Error: docker service create --name 'filebeat' returned 1 instead of one of [0]
Exec[Docker service create]/returns: change from notrun to 0 failed: docker service create --name 'filebeat' returned 1 instead of one of [0]

should services.pp be set to
if $create == 'true' {
instead of
if $create {

and the same for
if $update {
and
if $scale {

`docker daemon` is not supported on Linux. Please run `dockerd` directly error on RedHat Linux

Hi,

We are running Puppet 4.10.5 on RHEL7.3 (Linux 3.10.0-693.5.2.el7.x86_64 # 1 SMP Fri Oct 13 10:46:25 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux)

Using puppetlabs-docker version 1.0.1
and this Puppet code:

  class { 'docker':
    proxy    => lookup('common_data::proxy_url'),
    repo_opt => ''
  }
  • the proxy value is read from hiera (this bit works)
  • the repo_opt has to be there, otherwise we get another errors (Error: Execution of '/bin/yum -d 0 -e 0 -y --enablerepo=rhel7-extras install docker-engine' returned 1: Error getting repository data for rhel7-extras, repository not found)

It does install docker package:

Notice: /Stage[main]/Docker::Install/Package[docker]/ensure: created

... but it fails to start the service:

[root@hostname ~]# puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for hostname.azure.hiscox.com
Info: Applying configuration version '1510856660'
Notice: /Stage[main]/Docker::Install/Package[docker]/ensure: created
Notice: /Stage[main]/Docker::Service/File[/etc/systemd/system/docker.service.d/service-overrides.conf]/seltype: seltype changed 'systemd_unit_file_t' to 'container_unit_file_t'
Info: /Stage[main]/Docker::Service/File[/etc/systemd/system/docker.service.d/service-overrides.conf]: Scheduling refresh of Exec[docker-systemd-reload-before-service]
Notice: /Stage[main]/Docker::Service/Exec[docker-systemd-reload-before-service]: Triggered 'refresh' from 1 events
Error: Systemd start for docker failed!
journalctl log for docker:
-- Logs begin at Wed 2017-11-15 16:47:21 GMT, end at Fri 2017-11-17 08:40:22 GMT. --
Nov 17 08:40:22 hostname systemd[1]: Starting Docker Application Container Engine...
Nov 17 08:40:22 hostname docker[110449]: `docker daemon` is not supported on Linux. Please run `dockerd` directly
Nov 17 08:40:22 hostname systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Nov 17 08:40:22 hostname systemd[1]: Failed to start Docker Application Container Engine.
Nov 17 08:40:22 hostname systemd[1]: Unit docker.service entered failed state.
Nov 17 08:40:22 hostname systemd[1]: docker.service failed.

Error: /Stage[main]/Docker::Service/Service[docker]/ensure: change from stopped to running failed: Systemd start for docker failed!
journalctl log for docker:
-- Logs begin at Wed 2017-11-15 16:47:21 GMT, end at Fri 2017-11-17 08:40:22 GMT. --
Nov 17 08:40:22 hostname systemd[1]: Starting Docker Application Container Engine...
Nov 17 08:40:22 hostname docker[110449]: `docker daemon` is not supported on Linux. Please run `dockerd` directly
Nov 17 08:40:22 hostname systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Nov 17 08:40:22 hostname systemd[1]: Failed to start Docker Application Container Engine.
Nov 17 08:40:22 hostname systemd[1]: Unit docker.service entered failed state.
Nov 17 08:40:22 hostname systemd[1]: docker.service failed.

Info: Class[Docker::Service]: Unscheduling all events on Class[Docker::Service]
Info: Class[Docker]: Unscheduling all events on Class[Docker]
Info: Stage[main]: Unscheduling all events on Stage[main]
Notice: Applied catalog in 9.74 seconds 

We get the same error when attempting to start the service manually service docker start.

Nov 17 08:59:08 hostname systemd[1]: Unit docker.service entered failed state.
Nov 17 08:59:08 hostname systemd[1]: docker.service failed.
Nov 17 08:59:08 hostname systemd[1]: docker.service holdoff time over, scheduling restart.
Nov 17 08:59:08 hostname systemd[1]: start request repeated too quickly for docker.service
Nov 17 08:59:08 hostname systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit docker.service has failed.
--
-- The result is failed.

How to fix this? We are running it on Linux.

No Compose v.3 support

Can we please add support for Docker-Compose File Version 3.0 and above?

Error: Execution of '/usr/local/bin/docker-compose -f /media/data/docker-compose.yml up -d' returned 1: Version in "/media/data/docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a version of "2" (or "2.0") and place your service definitions under the 'services' key, or omit the 'version' key and place your service definitions at the root of the file to use version 1.

The latest release is backwards compatible

linux-image-extra not available on AWS server

Error:

Error: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install linux-image-extra-4.4.0-1039-aws' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package linux-image-extra-4.4.0-1039-aws
E: Couldn't find any package by glob 'linux-image-extra-4.4.0-1039-aws'
E: Couldn't find any package by regex 'linux-image-extra-4.4.0-1039-aws'
Error: /Stage[main]/Docker::Install/Package[linux-image-extra-4.4.0-1039-aws]/ensure: change from purged to present failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install linux-image-extra-4.4.0-1039-aws' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package linux-image-extra-4.4.0-1039-aws
E: Couldn't find any package by glob 'linux-image-extra-4.4.0-1039-aws'
E: Couldn't find any package by regex 'linux-image-extra-4.4.0-1039-aws'

I've temporarily patched this by setting $manage_kernel => false, but seems to be an issue.

APT dependency cycle

there is a dependency cycle which seems to be caused by this line, as the apt::source docker requires a package, which would be installed after apt::update, which requires apt::source..

require => Package['debian-keyring', 'debian-archive-keyring'],

formatted output:

(Anchor[apt_key 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 present] =>
Apt::Key[Add key: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 from Apt::Source docker] =>
Apt::Source[docker] =>
Class[Apt::Update] =>
Exec[apt_update] =>
Class[Apt::Update] =>
Package[debian-keyring] =>
Apt::Source[docker] =>
Apt::Key[Add key: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 from Apt::Source docker] =>
Anchor[apt_key 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 present])

Huge module size in 1.0.4

The 1.0.4 release grew a lot:

.../dist/puppet-modules$ ls -lh *.tar.gz
-rw-r--r-- 1 htj staff 67K Jan 12 14:26 puppetlabs-docker-1.0.2.tar.gz
-rw-r--r--@ 1 htj staff 1.7M Jan 15 14:29 puppetlabs-docker-1.0.4.tar.gz

Looks like it includes several other modules:

$ ls puppetlabs-docker-1.0.4/spec/fixtures/modules/
apt docker epel stdlib

$ du -hs puppetlabs-docker-1.0.4/spec/fixtures/modules/
4.5M puppetlabs-docker-1.0.4/spec/fixtures/modules/

Is this intentional?

Remove containers

Once a container is started with docker::run is there anyway to stop and remove it? I can't see anything in the docs, I imagine something like:

docker::run{'service':
  ensure => absent
}

Which should stop and remove all the associated systemd services etc as well.

Even better would be a purge option on the main class that automatically removed any containers that weren't specified in a docker::run statement.

When are container scheduled for refresh?

I am using puppetlabs-docker (v1.0.4) with puppet 4.10.9 on RHEL 7.4. My problem is that I can not figure out when containers are scheduled for refresh. If I change the docker::run configuration for some of many containers running on a host sometimes all running containers are scheduled for refresh (meaning restartet). I expect that restart for containers with changes in configuration but all other should stay untouched.

So far I see no reason in restarting all containers on a host. What am I missing and how can I prevent all untouched containers from restarting?

docker service update and scale not working, easy fix inside

docker service scale
Do not need to call docker_service_flags.rb function to compose service flags variable.
A simple fix is to change $exec_scale to "${docker_command} scale ${service_name}=${replicas}"

docker service update
docker_service_flags.rb checks if host_socket param is a string with value 'undef' and adds a flag with host_socket value if it is not. Since host_socket parameter is not passed when the function is called it is empty, so docker_service_flags always adds -H ''' to update command

host_socket parameter should be added when calling the function
$docker_service_flags = docker_service_flags({
detach => $detach,
env => $env,
service_name => $service_name,
label => $label,
publish => $publish,
replicas => $replicas,
tty => $tty,
user => $user,
workdir => $workdir,
extra_params => any2array($extra_params),
image => $image,
host_socket => $host_socket,
})

Can't declare more then one docker::secrets in the same catalog

When declaring more then two docker::secrets resources the module will throw an error like this

...
Duplicate declaration: Exec[docker secret create]
...

This happens because exec statement doens't include $title in its name.
I'm managing to fix this and will submit a PR soon

Failed to fetch https://download.docker.com/linux/ubuntu/dists/trusty/InRelease Unable to find expected entry 'stable/binary-i386/Packages'

The /etc/apt/sources.list.d/docker.list which this module creates is simple:

root@toma:~# cat /etc/apt/sources.list.d/docker.list 
# This file is managed by Puppet. DO NOT EDIT.
# docker
deb https://download.docker.com/linux/ubuntu trusty stable

The problem is that there is no empty i386 list - there wouldn't be an i386 docker, but Apt still looks even though the arch is x86_64

If I add [arch=amd64] to force the architecture, all works well.

deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable

This reference to the forced arch= is mentioned in the docs.
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/#set-up-the-repository

Is there any chance this could be added, based of course on the actual architecture detected?

At the moment I need to run a 'sed' script to manually modify the file any time I want to update packages, as apt fails looking for the missing i386 repository for Trusty.

docker::registry fails if $version is not explicitly set

puppet version: 4.10.9
module version: 1.0.2

Error while evaluating a Resource Statement, Evaluation Error: Left match operand must result in a String value. Got an Undef Value. at /etc/puppetlabs/code/environments/production/modules/docker/manifests/registry.pp:47:74

$version is set to undef in params.pp:
https://github.com/puppetlabs/puppetlabs-docker/blob/master/manifests/registry.pp#L43
https://github.com/puppetlabs/puppetlabs-docker/blob/master/manifests/params.pp#L6

Dependency cycle with repository config

I'm trying to investigate better what may causing this cycle. This happens with other profiles interactions. Seems like something relate with Exec['apt-update'] -> Package <||> but I'm not sure.
If any additional information is needed please let me now

Error: Failed to apply catalog: Found 1 dependency cycle:
(Anchor[apt_key 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 present] =>
 Apt::Key[Add key: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 from Apt::Source docker] =>
 Apt::Source[docker] => 
 Package[debian-keyring] => 
 Apt::Source[docker] => 
 Apt::Key[Add key: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 from Apt::Source docker] => 
 Anchor[apt_key 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 present])

cycles

I'm using puppetlabs/apt version 2.4.0

swarm legacy (docker 17.05) package regex doesn't match package pattern for centos

The package available from docker for centos 7 is...

17.05.0.ce-1.el7.centos

due to this, the regex at line 540 in init.pp needs to be updated...

if ( $version == undef ) or ( $version !~ /^(17[.]0[0-5][.]\d(~|-)ce|1.\d+)/ ) {

if ( $version == undef ) or ( $version !~ /^(17[.]0[0-5][.]\d(~|-)ce|1.\d+)/ ) {
I believe should be...
if ( $version == undef ) or ( $version !~ /^(17[.]0[0-5][.]\d(~|-|\.)ce|1.\d+)/ ) {
I'll submit a pull request shortly w/ the change.

Unknown resource type: 'apt::source'

This is my first go at using managing Docker with Puppet, so I could be doing something obviously wrong! But, when trying use/setup docker on Ubuntu 16.04 client I get:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, 
Unknown resource type: 'apt::source' at /etc/puppetlabs/code/environments/dev/modules/docker/manifests/repos.pp:23:9 on node X

Puppetfile:

forge "http://forge.puppetlabs.com"

# Modules from the Puppet Forge
# Versions should be updated to be the latest at the time you start
mod "puppetlabs/inifile",     '1.5.0'
mod "puppetlabs/stdlib",      '4.11.0'
mod "puppetlabs/concat",      '2.1.0'
mod 'puppetlabs-docker', '1.0.2'
mod 'puppetlabs-apt', '3.0.0'
mod 'stahnma-epel', '1.3.0'

Manifest common.pp:

class profile::docker::common (
  ) {
  include docker
   }

docker-run.erb has service name hard-coded to docker.service

This causes problems if/when setting package_name => 'docker-latest' and service_name => 'docker-latest'. An easy workaround is to set restart => 'always' in docker::run_instance::instance, but I would like to use systemd restart specific docker instances without having to completely restart docker.

Change package manager from 'rpm' to 'yum' for RedHat

Hi,

When docker is installed in install.pp on RedHat (RHEL7.3) and package_source is defined, then it's using 'rpm' as a package manager - see:

$pk_provider = 'rpm'

Unfortunately it seems that rpm does not install dependencies (unlike 'yum') and produces the following error:

Info: Using configured environment 'production' 
Info: Retrieving pluginfacts 
Info: Retrieving plugin 
Info: Loading facts 
Info: Caching catalog for *** 
Info: Applying configuration version '1511187653' 
Notice: /Stage[main]/Profile::Docker_swarm/File[/data]/seltype: seltype changed 'unlabeled_t' to 'default_t' 
Error: Execution of '/bin/rpm -i https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm' returned 1: warning: /var/tmp/rpm-tmp.OoQTV6: Header V4 RSA/SHA512 Si
gnature, key ID 621e9f35: NOKEY 
error: Failed dependencies: 
 container-selinux >= 2.9 is needed by docker-ce-17.09.0.ce-1.el7.centos.x86_64 
 libltdl.so.7()(64bit) is needed by docker-ce-17.09.0.ce-1.el7.centos.x86_64 
Error: /Stage[main]/Docker::Install/Package[docker]/ensure: change from absent to present failed: Execution of '/bin/rpm -i https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.0.ce-1.e
l7.centos.x86_64.rpm' returned 1: warning: /var/tmp/rpm-tmp.OoQTV6: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY 
error: Failed dependencies: 
 container-selinux >= 2.9 is needed by docker-ce-17.09.0.ce-1.el7.centos.x86_64 
 libltdl.so.7()(64bit) is needed by docker-ce-17.09.0.ce-1.el7.centos.x86_64 
Notice: /Stage[main]/Docker::Service/File[/etc/sysconfig/docker-storage-setup]: Dependency Package[docker] has failures: true 
Warning: /Stage[main]/Docker::Service/File[/etc/sysconfig/docker-storage-setup]: Skipping because of failed dependencies 
Notice: /Stage[main]/Docker::Service/File[/etc/systemd/system/docker.service.d]: Dependency Package[docker] has failures: true 
Warning: /Stage[main]/Docker::Service/File[/etc/systemd/system/docker.service.d]: Skipping because of failed dependencies 
Notice: /Stage[main]/Docker::Service/File[/etc/systemd/system/docker.service.d/service-overrides.conf]: Dependency Package[docker] has failures: true 
Warning: /Stage[main]/Docker::Service/File[/etc/systemd/system/docker.service.d/service-overrides.conf]: Skipping because of failed dependencies 
Notice: /Stage[main]/Docker::Service/Exec[docker-systemd-reload-before-service]: Dependency Package[docker] has failures: true 
Warning: /Stage[main]/Docker::Service/Exec[docker-systemd-reload-before-service]: Skipping because of failed dependencies 
Notice: /Stage[main]/Docker::Service/File[/etc/sysconfig/docker-storage]: Dependency Package[docker] has failures: true 
Warning: /Stage[main]/Docker::Service/File[/etc/sysconfig/docker-storage]: Skipping because of failed dependencies 
Notice: /Stage[main]/Docker::Service/File[/etc/sysconfig/docker]: Dependency Package[docker] has failures: true 
Warning: /Stage[main]/Docker::Service/File[/etc/sysconfig/docker]: Skipping because of failed dependencies 
Notice: /Stage[main]/Docker::Service/Service[docker]: Dependency Package[docker] has failures: true 
Warning: /Stage[main]/Docker::Service/Service[docker]: Skipping because of failed dependencies 
Info: Class[Profile::Docker_swarm]: Unscheduling all events on Class[Profile::Docker_swarm] 
Info: Stage[main]: Unscheduling all events on Stage[main] 

Cheers,
Miro

error while resolving custom fact

Error: Facter: error while resolving custom fact "docker_client_version": undefined method []' for nil:NilClass Error: Facter: error while resolving custom fact "docker_server_version": undefined method []' for nil:NilClass

docker::registry is called every time

Hi there,

When using docker::registry, this resource is called at every catalogue.

A little hack :

  if $receipt {
    # no - with pw_hash
    $local_user_strip = regsubst($local_user, '-', '', 'G')

    file { "/root/.docker/registry-auth-puppet_receipt_${server}_${local_user}":
      ensure  => $ensure,
      content => pw_hash("${title}${auth_environment}${auth_cmd}${local_user}", 'SHA-512', $local_user_strip),
      notify  => Exec["${title} auth"],
    }
  }

  exec { "${title} auth":
    environment => $auth_environment,
    command     => $auth_cmd,
    user        => $local_user,
    cwd         => '/root',
    path        => ['/bin', '/usr/bin'],
    timeout     => 0,
    refreshonly => $receipt,
  }```

Centos package obsoleted

I tried to install docker-ce version 17.03.2.ce-1.el7.centos, but got this error :

Error: Package: docker-ce-17.03.2.ce-1.el7.centos.x86_64 (docker)
           Requires: docker-ce-selinux >= 17.03.2.ce-1.el7.centos
           Available: docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch (docker)
               docker-ce-selinux = 17.03.0.ce-1.el7.centos
           Available: docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch (docker)
               docker-ce-selinux = 17.03.1.ce-1.el7.centos
           Available: docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch (docker)
               docker-ce-selinux = 17.03.2.ce-1.el7.centos
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
Error: /Stage[main]/Docker::Install/Package[docker]/ensure: change from purged to 17.03.2.ce-1.el7.centos failed: Could not update: Execution of '/bin/yum -d 0 -e 0 -y --enablerepo=extras install docker-ce-17.03.2.ce-1.el7.centos' returned 1: Package docker-ce-selinux is obsoleted by docker-ce, but obsoleting package does not provide for requirements
Error: Package: docker-ce-17.03.2.ce-1.el7.centos.x86_64 (docker)
           Requires: docker-ce-selinux >= 17.03.2.ce-1.el7.centos
           Available: docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch (docker)
               docker-ce-selinux = 17.03.0.ce-1.el7.centos
           Available: docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch (docker)
               docker-ce-selinux = 17.03.1.ce-1.el7.centos
           Available: docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch (docker)
               docker-ce-selinux = 17.03.2.ce-1.el7.centos
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

I saw a solution that consist of adding this option to the yum install command :

yum install -y --setopt=obsoletes=0 
docker-ce-17.03.2.ce-1.el7.centos 
docker-ce-selinux-17.03.2.ce-1.el7.centos

How can i use this module to install this version properly in centos7?
This version is the latest one supported by kubernetes...

Unable to Apply Engine Labels

/modules/docker/templates/etc/sysconfig/docker.systemd.erb
Line: 25
Detail: undefined method `each' for "[owner=blah, myservice=1, role=myrole]":String
at /etc/puppetlabs/code/environments/test/modules/docker/manifests/service.pp:193:18

Similar to $dns should be able to set the docker.systemd.erb template as
<% if @labels %><% @labels_array.each do |label| %> --label <%= label %><% end %><% end -%>

and add the below to service.pp
$labels_array = any2array($labels)

Unless I've missed something?

validate_re(): input needs to be a String

Hi,

When I try to include docker in my init.pp I will get the following error:

 Puppet::PreformattedError:
   Evaluation Error: Error while evaluating a Function Call, validate_re(): input needs to be a String, not a NilClass at C:/Users/vibh/WORKDIR/my_docker/spec/fixtures/modules/docker/manifests/init.pp

Stdlib Version :4.24.0
Puppet version: 4.10.9

Thanks,

Support Windows

Support installing docker and managing native windows containers on the windows server platform.

Commitment: 73 Merge Requests, 115 Issues, 154 contributors

garethr/docker, previously the upstream source of the the internal docker_platform resource in puppet, was last released in July of 2016. Since that time, the community of users have literally begged for support. They've even submitted over 70 Merge Requests to fix the glaring issues that make this module literally unusable unless you're using legacy docker and EoL version of puppet.

There have also been over 150 contributors that have participated in the current state of this module.

I realize the intent of bringing this module here wasn't to bring baggage from its history, but between the persistent absence of a response to any of the issues or MR's, in addition to getting rid of the badge acknowledgement of previous contributors in the history, this sends a message.

Can you please help us make sure we get the right message? Please provide answers to the following questions:

  • Does the creation of this module signify a commitment from puppetlabs to actively maintain this module?
  • Would it be possible for you take the most recent commits from this project and rebase them onto the commit history from garethr/docker?
  • Do you have plans to address or migrate Issues/PR's from garethr/docker to this module

Many of us have worked hard to make this module better, and we're willing to work with folks from puppetlabs wherever they ask us to. All we're ask for is two-way communication.

Thank you

Don't break systemd::dropin_file for Docker

With the docker module in place, attempting to add a systemd dropin file like;

systemd::dropin_file { '10-docker-proxy.conf':
  ensure  => file,
  content => epp("${module_name}/proxy/systemd-environment.epp", {
      host_fqdn => $host_fqdn,
      host_port => $proxy_host[parameters][port],
      proxy     => $proxy,
      no_proxy  => $no_proxy,
  }),
  unit    => 'docker.service',
}

Will cause compilation errors like;
Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, Duplicate declaration: File[/etc/systemd/system/docker.service.d] is already declared in file /etc/puppetlabs/code/environments/production/modules/docker/manifests/service.pp:150; cannot redeclare at /etc/puppetlabs/code/environments/production/modules/systemd/manifests/dropin_file.pp:52 at /etc/puppetlabs/code/environments/production/modules/systemd/manifests/dropin_file.pp:52:5 at /etc/puppetlabs/code/environments/production/modules/profiles/manifests/proxy/client.pp:27 on node example.com

Systemd escaping

Hello,

As already reported in the "Issues " of gareth-docker (#647 or #432 there is an issue with complex run commands under systemd.

I ran into the same issue, while adding JVM_ARGS to a docker container, for example
JVM_ARGS='-Xms2048m -Xmx2048m -XX:MaxDirectMemorySize=1g`

The patch provided in the previous issue, solves this issue.

Support for network in docker::run

Hi

After getting support for docker::network in 1.0.4, it would be nice if one could do network in docker::run instead of using extra_parameters, e.g.:

docker::run { 'whatever':
image => 'whatever:1.2.3.',
network => [ 'whatever-internal' ]
}

Swarm mode token

The documentation of a swarm mode setup seems to be missing something important.
It looks like to manage swarm with puppet I need to provision a token.
But to get the token I need to go to the manager node and type docker swarm join-token -q, copy the output and paste it into puppet?

Am I missing something? Or there's some automated way to do that?
What I would expect is this:

if(host_has_label("my-swarm-manager")) {
  docker::swarm {'cluster_manager':
    init           => true,
    advertise_addr => current_host_ip(),
    listen_addr    => current_host_ip(),
    swarm_name     => 'my-swarm'
  }
} else if (host_has_label("my-swarm-worker")) {
  docker::swarm {'cluster_worker':
    join           => true,
    advertise_addr => current_host_ip(),
    listen_addr    => current_host_ip(),
    manager_ip     => get_ip_by_swarm_name('my-swarm'),
    token          => get_token_by_swarm_name('my-swarm')
  }
}

Is there a tutorial on how to do something like this?

docker_socket should be tied to docker_group by default

If you look at the official docs for dockerd, you will see that there is a group setting for setting the permissions on the socket.

In the puppet module, there are separate docker_group and socket_group parameters that, in my mind, should be the same thing.

Could an explanation be provided as to why they are different and, if they should not be different by default, could socket_group be set to $docker_group by default in the module parameters?

Lookup of key 'lookup_options' failed: Data Provider type mismatch: Got String when a hash-like object was expected to access value using 'release' from key 'os.release.full'

Hi,

Currenly we are using garethr-docker forge module, which works fine, but we are having issues with garethr/garethr-docker#701, so therefore I'm in the process of changing to puppetlabs-docker instead.

Unfortunately I'm seeing an issue I have problem pinpointing. My test server is using only the profile::docker manifest with a Puppetfile just containing puppetlabs-docker and puppetlabs-stdlib. When the Puppet agent tries to apply the catalog it logs th error below. I found https://tickets.puppetlabs.com/browse/MODULES-4103, but not sure if it is relevant to this issue. I have tried the 1.0.4 version and the master branch, but the same error with both.

For info, the include profile::yum::docker_ce below just adds our internal YUM repository with the Docker CE RPMs.

Has anyone seen this issue and can point me in the right direction?

CentOS release

$ cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

Puppet version

$ puppet --version
4.10.9

Facter version

$ facter --version
3.6.8 (commit 25dace2536f6bd339b70b385c7e90e1951870671)

Puppetfile

mod 'puppetlabs-docker', '1.0.4'
mod 'puppetlabs-stdlib', '4.24.0'

Puppet manifest

class profile::docker {
  include profile::yum::docker_ce

  class { 'docker':
    use_upstream_package_source => false,
    package_ce_name             => 'docker-ce',
    manage_epel                 => false,
  }
}

Puppet log

Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, Lookup of key 'lookup_options' failed: Data Provider type mismatch: Got String when a hash-like object was expected to access value using 'release' from key 'os.release.full' at <path> on node <server>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.