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

Compose v3: Moved shared volume to top-level volumes entry #709

Closed
wants to merge 3 commits into from

Conversation

sjawhar
Copy link

@sjawhar sjawhar commented Feb 9, 2017

For compatibility for Docker Compose v3, replaced the unnamed volume in the nginx service with a named nginx_conf volume that is shared by both services.

https://docs.docker.com/compose/compose-file/#/upgrading

For compatibility for Docker Compose v3, replaced the unnamed volume in the nginx service with a named nginx_conf volume that is shared by both services.
@endersonmaia
Copy link

I get this error :

myservice_dockergen.1.07txurxupiwb@moby    | 2017/02/23 22:13:47 Cnable to create temp file: open /etc/nginx/conf.d/docker-gen327150582: no such file or directory

@sjawhar
Copy link
Author

sjawhar commented Feb 25, 2017

@endersonmaia That's strange, running docker-compose -f docker-compose-separate-containers.yml up -d works flawlessly for me on both Windows and CentOS 7. Are you running docker 1.13.0+? That's required for compose v3.

@teohhanhui
Copy link
Contributor

teohhanhui commented Apr 12, 2017

We have no real way of controlling which base image the files are copied from. So this may or may not work sometimes...

UPDATE: Actually, we can use the nocopy mount option.

volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
- nginx_conf:/etc/nginx/conf.d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- nginx-conf:/etc/nginx/conf.d:nocopy

This is to prevent Docker from copying the contents from the wrong container.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what you mean by "the wrong container"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker copies files from the image into the volume when starting the container.

If files are copied from the dockergen container into the nginx-conf volume, it'd become empty. This would happen when the dockergen container is started before the nginx container. Adding nocopy here ensures that files are never copied from this container.

Copy link
Author

@sjawhar sjawhar Apr 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it, and the volume is not emptied if it has data. Considering that the /etc/nginx/conf.d folder does not exist in jwilder/docker-gen, and considering that docker-gen is maintaining the contents of this volume anyway, can you explain your concern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Build an nginx image with your own configuration files in /etc/nginx/conf.d.
  2. Delete the containers and the volume.
  3. Start the dockergen service.
  4. Start the nginx service.

You'll see that the nginx-conf volume was initialized to empty from the dockergen image. Then it'll only have one default.conf after generation from template. Your own configuration files would be lost.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you make sure to start the dockergen service before the nginx service? Because startup order is not guaranteed, and that's why the problem could happen sometimes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was finally able to reproduce this issue, but adding nocopy doesn't fix it. If the problem is startup order, maybe the right solution is to add depends_on to the dockergen service?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure adding nocopy doesn't fix it? Because it works for me. You'll need to make sure to remove the volumes before each run to be able to test it properly.

depends_on has no effect when using docker stack deploy, so it's not a solution. (Basically we should not care about the startup order.) See moby/moby#31333

Copy link
Author

@sjawhar sjawhar Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. If I just run docker-compose up, the config files are there regardless of whether nocopy is added to the dockergen service. This is probably just luck, given the race condition you describe, though I tried a few dozen times.
  2. If I run docker-compose up dockergen then docker-compose up nginx, the config files are missing regardless of whether nocopy is added to the dockergen service.

Is there some other test I can run to verify the behavior you're describing?

Copy link
Author

@sjawhar sjawhar Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to think this is not actually an issue. If I need to make a custom Nginx image, couldn't I just place the config file somewhere other than /etc/nginx/conf.d? Problem solved.

Alternatively, we could use a /etc/nginx/dockergen folder, but then you'd need a derived Nginx image.


whoami:
image: jwilder/whoami
environment:
- VIRTUAL_HOST=whoami.local

volumes:
nginx_conf: {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nginx-conf, because that's the convention used by Docker.

For example here: https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-shared-storage-volume-as-a-data-volume (my-named-volume)

Copy link
Author

@sjawhar sjawhar Apr 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that Docker Compose names everything with an underscore ($PROJECT_default network, $PROJECT_$SERVICE_1 container, etc.), I'm not so sure about "convention." Doing that results in a volume called <project_name>_nginx-conf, which is just... ugly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's intended. The underscore is used for prefix (e.g. project name) and postfix (e.g. _default, _1). Using dash means it doesn't get mixed together with the prefix and postfix parts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree. This seems like an issue of standards. Maybe the project maintainers have an opinion? @jwilder

@@ -1,23 +1,25 @@
version: '2'
version: '3'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to bump the version here, so that it can still work with older Docker and Docker Compose versions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, no reason to rush to v3 until other Stack compatibility issues are fixed.

Copy link
Author

@sjawhar sjawhar Apr 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though version 3 is list as the recommended version
https://docs.docker.com/compose/compose-file/compose-versioning/

@sjawhar sjawhar closed this Feb 20, 2018
@sjawhar sjawhar deleted the patch-1 branch February 20, 2018 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants