docker工人 – 组成图像卷

我使用docker机,Mac OS X,驱动digitalocean和默认的virtualbox。

Dockerfile:

FROM ruby:2.2.0 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev RUN mkdir /myapp-web-api WORKDIR /myapp-web-api ADD Gemfile /myapp-web-api/Gemfile ADD Gemfile.lock /myapp-web-api/Gemfile.lock RUN bundle install ADD . /myapp-web-api 

泊坞窗,compose.yml:

 db: image: postgres ports: - "5432:5432" web: build: . command: rails s -p 3000 -b '0.0.0.0' volumes: - .:/myapp-web-api ports: - "3000:3000" links: - db 

当我使用本地的virtualbox驱动程序卷映射是好的。 但是当我将env切换到digitalocean开始与图像的一些问题。

docker构build可以

 Boriss-MacBook-myapp-web-api wwtlf$ docker-compose ps Name Command State Ports ------------------------------------------------------------------ myappwebapi_db_1 /docker-entrypoint.sh postgres Exit 0 myappwebapi_web_1 rails s -p 3000 -b 0.0.0.0 Exit 1 Boriss-MacBook-myapp-web-api wwtlf$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE myappwebapi_web latest 4c95e37708ff 22 minutes ago 927 MB postgres latest b305a133422a 13 days ago 265.1 MB ruby 2.2.0 ac90cee00759 10 months ago 774.7 MB Boriss-MacBook-Pro:myapp-web-api wwtlf$ 

当我尝试启动容器时:

 Boriss-MacBook-Pro:myapp-web-api wwtlf$ docker-compose up Starting myappwebapi_db_1 Starting myappwebapi_web_1 Attaching to myappwebapi_db_1, myappwebapi_web_1 db_1 | LOG: database system was shut down at 2015-12-19 07:34:21 UTC db_1 | LOG: MultiXact member wraparound protections are now enabled db_1 | LOG: database system is ready to accept connections db_1 | LOG: autovacuum launcher started web_1 | /usr/local/bundle/gems/bundler-1.7.12/lib/bundler/definition.rb:22:in `build': /myapp-web-api/Gemfile not found (Bundler::GemfileNotFound) web_1 | from /usr/local/bundle/gems/bundler-1.7.12/lib/bundler.rb:155:in `definition' web_1 | from /usr/local/bundle/gems/bundler-1.7.12/lib/bundler.rb:118:in `setup' web_1 | from /usr/local/bundle/gems/bundler-1.7.12/lib/bundler/setup.rb:17:in `<top (required)>' web_1 | from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require' web_1 | from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require' web_1 | from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require' web_1 | from /usr/local/bundle/bin/rails:14:in `<main>' myappwebapi_web_1 exited with code 1 

嗯,让我们来看看这些卷:

 docker-compose run web /bin/bash Starting myappwebapi_db_1 root@155e09fc57ac:/myapp-web-api# ls root@155e09fc57ac:/myapp-web-api# 

空:(我们试试另一种方式:

 Boriss-MacBook-Pro:myapp-web-api wwtlf$ docker run -i -t myappwebapi_web /bin/bash root@ee53fea29f97:/myapp-web-api# ls Dockerfile Gemfile Gemfile.lock README.rdoc Rakefile app bin config config.ru db docker-compose.yml lib log public test tmp vendor root@ee53fea29f97:/myapp-web-api# 

docker-compose运行和docker运行有什么区别???

看起来线我连接到不同的图像…

UPD:

我发现docker-compose运行web / bin / bash文件夹/ myapp-web-api已映射到digitalocean VM上的root @ myapp-prod: / Users / wwtlf / Projects / MYAPP / myapp-web-api文件夹,但不能主办。

docker-compose rundocker run什么区别???

不同之处在于docker-compose.yml文件的卷部分:

 volumes: - .:/myapp-web-api 

该命令将主机目录。,安装到/ myapp-web-api的容器中。
如果path/myapp-web-api已经存在于容器的映像中,那么./ mount会覆盖,但不会删除预先存在的内容

docker-compose up命令暂时覆盖Dockerfile ADD指令中指定的/myapp-web-api的内容。

docker run -i -t myappwebapi_web /bin/bash命令并没有装载任何主机文件夹。