Docker Community Forums

Share and learn in the Docker community.

Docker volumes initialized from container


(Ctammes) #1

I have a situation where I want to directly edit files in the container from an IDE running on dockerhost (Linux desktop).
I have an image (Ruby Rails) which does not contain the editable directories. So I start a container and use the -v switch like this:
-v host/application/codedir:/var/www/codedir.

The problem is, that, when creating the container with ‘docker run’, a script in the container creates /var/www/codedir and initializes code and directories inside (‘rails new myapp’). But for some reason directories and code is never created and the container doesn’t start. On the dockerhost however, the drectories application/codedir are created (using mkdir).
When I remove the -v switch from the docker run command and enter the container, the script runs flawlessly when started mannually.

Has this anything to do with permissions? Host directories are created as root.
Is it not possible to create directories in the container which are ‘copied’ to the host using -v?

In Dockerfile:
CMD /root/start_app.sh

start_app.sh:
mkdir -p /var/www
cd /var/www
rails new $RUBYAPP
cd $RUBYAPP
bundle install
rake db:create


(Ctammes) #2

Solved. Call to script wasn’t correct.