concept secret in category docker

appears as: secrets, secret, A secret, secrets, The secret
Learn Docker in a Month of Lunches

This is an excerpt from Manning's book Learn Docker in a Month of Lunches.

The Docker Compose format records all the properties you need to configure your app, and it can also record other top-level Docker resources like volumes and secrets. This app just has a single service, and even in this case it’s good to have a Compose file that you can use to run the app and to document its setup. But Compose really makes sense when you’re running multi-container apps.

I’m using override files to inject configuration for different environments, and I’m using different approaches for each item, so I can show you the options Docker Compose has. Listing 10.3 shows the core Compose file; this just has the basic information for the web application with a configuration file set up as a secret.

Listing 10.3 The Compose file specifies the web service with a secret

services:
   todo-web:
       image: diamol/ch06-todo-list
       secrets:
           - source: todo-db-connection
                 target: /app/config/secrets.json

Secrets are a useful way of injecting configuration--they have support in Docker Compose, Docker Swarm, and Kubernetes. In the Compose file you specify the source and target for the secret. The source is the place where the secret is loaded from the container runtime, and the target is the file path where the secret is surfaced inside the container.

This secret is specified as coming from the source todo-db-connection , which means there needs to be a secret with that name defined in the Compose file. The contents of the secret will be loaded into the container at the target path /app/config/ secrets.json , which is one of the locations the application searches for configuration settings.

The preceding Compose file on its own isn’t valid because there is no secrets section, and the todo-db-connection secret is required because it’s used in the service definition. Listing 10.4 shows the override file for development, which sets up some more configuration for the service and specifies the secret.

Figure 13.4 Applying configuration from the platform; Swarm mode uses config objects and secrets.
Docker in Action, Second Edition

This is an excerpt from Manning's book Docker in Action, Second Edition.

Table 9.1. Performance of public hosted repositories (view table figure)

Criteria

Rating

Notes

Cost Best Public repositories on hosted registries are almost always free. That price is difficult to beat. These are especially helpful when you’re getting started with Docker or publishing open source software.
Visibility Best Hosted registries are well-known hubs for software distribution. A public repository on a hosted registry is an obvious distribution choice if you want your project to be well-known and visible to the public.
Transport speed/size Better Hosted registries such as Docker Hub are layer-aware and will work with Docker clients to transfer only the layers that the client doesn’t already have. Further, pull operations that require multiple repositories to be transferred will perform those transfers in parallel. For those reasons, distributing an image from a hosted repository is fast, and the payloads are minimal.
Longevity control Good You have no longevity control over hosted registries. But registries will all conform to the Docker registry API, and migrating from one host to another should be a low-cost exercise.
Availability control Worst You have no availability control over hosted registries.
Access control Better Public repositories are open to the public for read access. Write access is still controlled by whatever mechanisms the host has put in place. Write access to public repositories on Docker Hub is controlled in two ways. First, repositories owned by an individual may be written to only by that individual account. Second, repositories owned by organizations may be written to by any user who is part of that organization.
Artifact integrity Best The current version of the Docker registry API, V2, provides content-addressable images. The V2 API lets you request an image with a specific cryptographic signature. The Docker client will validate the integrity of the returned image by recalculating the signature and comparing it to the one requested. Old versions of Docker that are unaware of the V2 registry API don’t support this feature and use V1 instead. In those cases, and for other cases where signatures are unknown, a high degree of trust is put into the authorization and at-rest security features provided by the host.
Confidentiality Worst Hosted registries and public repositories are never appropriate for storing and distributing cleartext secrets or sensitive code. Remember, secrets include passwords, API keys, certificates, and more. Anyone can access these secrets.
Requisite experience Best Using public repositories on hosted registries requires only that you be minimally familiar with Docker and capable of setting up an account through a website. This solution is within reach for any Docker user.

This chapter will show you how to use Docker’s configuration and secret resources to adapt Docker service deployments according to various deployment needs. Docker’s first-class resources for modeling configuration and secrets will be used to deploy a service with different behavior and features, depending on which environment it is deployed to. You will see how the naive approach for naming configuration resources is troublesome and learn about a pattern for solving that problem. Finally, you will learn how to safely manage and use secrets with Docker services. With this knowledge, you will deploy the example web application with an HTTPS listener that uses a managed TLS certificate.

version: '3.7'

configs:
  env_specific_config:
    file: ./api/config/config.${DEPLOY_ENV:-prod}.yml           #1

services:

  api:
      image: ${IMAGE_REPOSITORY:-dockerinaction/ch12_greetings}:api
      ports:
        - '8080:8080'
        - '8443:8443'
      user: '1000'
      configs:
        - source: env_specific_config
          target: /config/config.${DEPLOY_ENV:-prod}.yml        #2
          uid: '1000'
          gid: '1000'
          mode: 0400 #default is 0444 - readonly for all users
      secrets: []
      environment:
        DEPLOY_ENV: ${DEPLOY_ENV:-prod}

Notice that there is no Data field as there was with a config resource. The secret’s value is not available via the Docker tools or Docker Engine API. The secret’s value is guarded closely by the Docker Swarm control plane. Once you load a secret into Swarm, you cannot retrieve it by using the docker CLI. The secret is available only to services that use it. You may also notice that the secret’s spec does not contain any labels, as it is managed outside the scope of a stack.