Home Explore Blog CI



docker

4th chunk of `content/manuals/engine/swarm/configs.md`
710f65d58af0ce8cda44f924f3afd6ab22d820476527345c0000000100000fa1
    fzwcfuqjkvo5foqu7ts7ls578   hello               31 minutes ago      31 minutes ago


    $ docker config rm my-config

    Error response from daemon: rpc error: code = 3 desc = config 'my-config' is
    in use by the following service: redis
    ```

6.  Remove access to the config from the running `redis` service by updating the
    service.

    ```console
    $ docker service update --config-rm my-config redis
    ```

7.  Repeat steps 3 and 4 again, verifying that the service no longer has access
    to the config. The container ID is different, because the
    `service update` command redeploys the service.

    ```none
    $ docker container exec -it $(docker ps --filter name=redis -q) cat /my-config

    cat: can't open '/my-config': No such file or directory
    ```

8.  Stop and remove the service, and remove the config from Docker.

    ```console
    $ docker service rm redis

    $ docker config rm my-config
    ```

### Simple example: Use configs in a Windows service

This is a very simple example which shows how to use configs with a Microsoft
IIS service running on Docker for Windows running Windows containers on
Microsoft Windows 10.  It is a naive example that stores the webpage in a config.

This example assumes that you have PowerShell installed.

1.  Save the following into a new file `index.html`.

    ```html
    <html lang="en">
      <head><title>Hello Docker</title></head>
      <body>
        <p>Hello Docker! You have deployed a HTML page.</p>
      </body>
    </html>
    ```
 
2.  If you have not already done so, initialize or join the swarm.

    ```powershell
    docker swarm init
    ```

3.  Save the `index.html` file as a swarm config named `homepage`.

    ```powershell
    docker config create homepage index.html
    ```

4.  Create an IIS service and grant it access to the `homepage` config.

    ```powershell
    docker service create
        --name my-iis
        --publish published=8000,target=8000
        --config src=homepage,target="\inetpub\wwwroot\index.html"
        microsoft/iis:nanoserver
    ```

5.  Access the IIS service at `http://localhost:8000/`. It should serve
    the HTML content from the first step.

6.  Remove the service and the config.

    ```powershell
    docker service rm my-iis

    docker config rm homepage
    ```

### Example: Use a templated config

To create a configuration in which the content will be generated using a
template engine, use the `--template-driver` parameter and specify the engine
name as its argument. The template will be rendered when container is created.

1.  Save the following into a new file `index.html.tmpl`.

    ```html
    <html lang="en">
      <head><title>Hello Docker</title></head>
      <body>
        <p>Hello {{ env "HELLO" }}! I'm service {{ .Service.Name }}.</p>
      </body>
    </html>
    ```

2.  Save the `index.html.tmpl` file as a swarm config named `homepage`. Provide
    parameter `--template-driver` and specify `golang` as template engine.

    ```console
    $ docker config create --template-driver golang homepage index.html.tmpl
    ```

3.  Create a service that runs Nginx and has access to the environment variable
    HELLO and to the config.

    ```console
    $ docker service create \
         --name hello-template \
         --env HELLO="Docker" \
         --config source=homepage,target=/usr/share/nginx/html/index.html \
         --publish published=3000,target=80 \
         nginx:alpine
    ```

4.  Verify that the service is operational: you can reach the Nginx server, and
    that the correct output is being served.

    ```console
    $ curl http://0.0.0.0:3000

    <html lang="en">
      <head><title>Hello Docker</title></head>
      <body>
        <p>Hello Docker! I'm service hello-template.</p>
      </body>
    </html>
    ```

### Advanced example: Use configs with a Nginx service

This example is divided into two parts.
[The first part](#generate-the-site-certificate) is all about generating

Title: Docker Config Examples: Windows Service, Templated Config, and Advanced Nginx Usage
Summary
This section continues with Docker config examples, including a simple demonstration of using configs with a Windows IIS service, creating a templated config, and a setup for using configs with an Nginx service. The Windows example covers creating an HTML file, initializing the swarm, saving the HTML as a config, creating an IIS service with access to the config, accessing the service, and removing the service and config. The templated config example shows how to create a dynamic configuration using a template engine, create a service with access to the config and environment variables, and verify the service's output. The last example mentions being divided into two parts and focuses on generating a site certificate for Nginx.