[英]docker-compose images volumes
我正在使用docker-machine,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-compose构建是可以的
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 run有什么区别???
看起来我连接到其他图像的线...
UPD:
我发现docker-compose run web / bin / bash文件夹/ myapp-web-api已映射到root @ myapp-prod:digitalocean VM上的/ Users / wwtlf / Projects / MYAPP / myapp-web-api文件夹,但未映射到主办。
docker-compose run
和docker run
什么区别?
区别在于docker-compose.yml文件的卷部分:
volumes:
- .:/myapp-web-api
此命令将主机目录。挂载到/ myapp-web-api的容器中。
如果路径/myapp-web-api
已存在于容器的映像中,则./
mount会覆盖但不会删除先前存在的内容 。
docker-compose up
命令会临时覆盖Dockerfile ADD
指令中指定的/myapp-web-api
的内容。
docker run -i -t myappwebapi_web /bin/bash
命令不是这种情况,该命令不会挂载任何主机文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.