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

Container volume masks host volume in the compose file #2308

Closed
mekanixdk opened this issue Nov 3, 2015 · 6 comments
Closed

Container volume masks host volume in the compose file #2308

mekanixdk opened this issue Nov 3, 2015 · 6 comments

Comments

@mekanixdk
Copy link

I have a little snippet in docker-compose.yml like:

volumes:
  - ${HOST_PATH}:/container/path

If I change the value of HOST_PATH any subsequent up or build, the container will still mount the volume with the old value of HOST_PATH.

Is this because volumes is not a run time option like docker -v or is this a bug?

@dnephin
Copy link

dnephin commented Nov 3, 2015

I can't reproduce this issue with master .What version of docker-compose are you running?

Here's what I ran:

web:                                                                                                                                                                                                                                                                              
  image: 'alpine:edge'                                                                                                                                                                                                                                                            
  volumes:                                                                                                                                                                                                                                                                        
    - '${HOST_PATH}:/contents'                                                                                                                                                                                                                                                    
  command: 'ls /contents'   
HOST_PATH=`pwd`/examples docker-compose up
# Prints the list of files in examples

HOST_PATH=. docker-compose up
# Prints a different list of files in the current directory

@mekanixdk
Copy link
Author

I was using 1.5.0 RC1 and RC2. I can see that 1.5.0 have just been released. I will try that with your example above.

My container looks like this:

mysql:
  container_name:
    dungbeetle_mysql
  image:
    mysql:5.6
  environment:
    MYSQL_ROOT_PASSWORD: password
  expose:
    - "3306"
  ports:
    - "3306:3306"
  volumes:
    - ${DUNGBEETLE_MYSQL_DATA}:/var/lib/mysql
  hostname: database

@mekanixdk
Copy link
Author

@dnephin you example worked like you said.

I am a noob regarding docker, but here is a theory of what I am seeing.

In the mysql Dockerfile VOLUME is defined (VOLUME /var/lib/mysql), and as I read the docs the container creates that "volume" on the host /somewhere/where/docker/containers/are/stored/too

In docker-compose.yml I define:

volumes:
  - ${HOST_PATH}:/var/lib/mysql

Ie. I try to define where that "volume" should be located on the host.

It appears like this overwrite the VOLUME in Dockerfile, and consequently at build time I can define my own path.

At runtime the /var/lib/mysql is already defined/mounted so the ${HOST_PATH}:/var/lib/mysql is ignored (I don't see any errors or warnings that this should be the case though.).

@mekanixdk
Copy link
Author

So the solution for me seems to change the default location of the DB from /var/lib/mysql to something I control.

Question though... is this expected behaviour? It isn't clear from reading the docs (well, I expected something else :-))

@dnephin
Copy link

dnephin commented Nov 4, 2015

It is by design. I recently added this paragraph to the docs, to try and call attention to it: http://docs.docker.com/compose/#preserve-volume-data-when-containers-are-created

But I think it could use more detail

@dnephin
Copy link

dnephin commented Nov 4, 2015

Maybe we can add a warning when there's a host volume that is going to be ignored for the container volume. I think that would be better than adding documentation that users will have to find.

@dnephin dnephin added this to the 1.5.1 milestone Nov 4, 2015
@dnephin dnephin self-assigned this Nov 4, 2015
@dnephin dnephin changed the title Value change in environment variables are not propagated to container. Container volume masks host volume in the compose file Nov 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants