docker / compose

Define and run multi-container applications with Docker
https://docs.docker.com/compose/
Apache License 2.0
33.98k stars 5.22k forks source link

Feature: inline file #3538

Closed pierreozoux closed 5 years ago

pierreozoux commented 8 years ago

I create a lot of compose file that I hope are useful for the community. I'd like to find a way for docker to officially ship these compose files.

There is one issue that IMHO is blocking us of doing so, is the ability to ship a file in docker-compose. Indeed, what distinguish a piwik from an ownCloud from a WordPress compose file is only the nginx configuration.

There are 3 way that I know to ship this configuration:

The first option: a file on the host:

  volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf:ro

The second option: the current inline way:

web:
  image: nginx
  volumes:
    - ./data:/var/www/html
  command: |
    bash -c 'bash -s <<EOF
      cat > /etc/nginx/nginx.conf <<EON
        daemon off;
        user www-data;
        events {
          worker_connections 768;
        }
        http {
          gzip on;
          gzip_disable "msie6";
          include /etc/nginx/mime.types;
          server {
            listen 80;
            root /var/www/html;
            index index.html;
          }
        }
    EON
    nginx
    EOF'

A bit dirty

The 3rd way: inline file

web:
  image: nginx
  volumes:
    - ./data:/var/www/html
  files:
    -   owner: root:root
        path: /etc/nginx/nginx.conf
        permissions: '0644'
        content: |
         user www-data;
          events {
            worker_connections 768;
          }
          http {
            gzip on;
            gzip_disable "msie6";
            include /etc/nginx/mime.types;
            server {
              listen 80;
              root /var/www/html;
              index index.html;
            }
          }

And so, I'm sure you see the value to have a proper way to add inline file.

The syntax could be similar to what cloudinit does.

With this, it would become easier to ship one compose file with everything included to get started an app!

bweston92 commented 6 years ago

Would also help not over-engineering something. I have to use Docker configs for snippets of configuration when really it would be easier/portable in a single YAML file.

So for configs you could have something as follows:

version: '3.3'
services:
  postgresql:
    image: postgresql
    configs:
      - target: /postrgresql_config
        uid: '103'
        gid: '103'
        mode: 0440
        content: |
          myconfig: $(YOU)
          value: $(CAN) 
          other: $(TEMPLATIZE)
Fridus commented 5 years ago

@shin- Hi, any solution ?

shin- commented 5 years ago

@Fridus Check out https://github.com/docker/app !

ijc commented 5 years ago

Issue grooming: I think I agree with @shin- that this sounds more like a docker-app thing.

adams-family commented 3 years ago

+1

I'd like that, too!

brunocascio commented 3 years ago

Me too here :(

MrBuddyCasino commented 2 years ago

Inline files would also make it much easier to run docker compose on a remote host. Since docker app isn't a thing anymore, maybe reconsider closing this issue?

wauwau0977 commented 2 years ago

Would like that too... k8s offers that as well, would like to see it in docker compose.

dmckernanacv commented 2 years ago

Bumping this, hard to believe it's not a thing, would be extremely useful.

ezk84 commented 2 years ago

+1. This would be useful.

Mimikoo commented 1 year ago

Any info on this?

srstsavage commented 1 year ago

https://github.com/compose-spec/compose-spec/issues/346

Please upvote if you'd like to see this implemented

bergkvist commented 11 months ago

This is available in Docker Compose version 2.23.1 now.

name: config-inline
services:
  service:
    image: ubuntu
    entrypoint: cat
    command: /path/to/config.txt
    configs:
      - source: config.txt
        target: /path/to/config.txt
configs:
  config.txt:
    content: |
      strawberry fields forever

Output:

$ docker-compose up
[+] Building 0.0s (0/0)                                                                   docker:default
[+] Running 2/0
 ✔ Network config-inline_default      Created                                                       0.0s 
 ✔ Container config-inline-service-1  Created                                                       0.0s 
Attaching to service-1
service-1  | strawberry fields forever
service-1 exited with code 0
srstsavage commented 11 months ago

This is great, and will make many deployments much simpler and cleaner. Thank you @ndeloof!

sergioisidoro commented 9 months ago

This is super great! I've been waiting for this for so long :D I've updated compose and works great.

However the I was a bit disappointed to discover that the spec does not yet seem to be available on swarm deploy, on engine 25.0.1. https://github.com/compose-spec/compose-spec/issues/346#issuecomment-1826282162

glours commented 9 months ago

Hello @sergioisidoro Swarm isn't supported by Docker anymore but by Mirantis, maybe you could open an issue into the moby/moby project

sergioisidoro commented 9 months ago

Thanks @glours , I opened a issue in a sort of hail Mary :) from what I see from Mirantis' website, their focus seems to be mainly on Kubernetes, with no mention of swarm as a solution. I'm afraid this is going towards a dead end.