我使用的是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
当我使用本地虚拟机驱动程序卷时,映射很好。但是当我将env切换到digitalocean时,会出现一些图像问题。
docker-compose 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 run和docker run ???
之间的区别是什么?看起来我连接到不同的图像......
UPD:
我找到了 docker-compose运行web / bin / bash 文件夹 / myapp-web-api 已映射到digitalocean VM上的root @ myapp-prod: / Users / wwtlf / Projects / MYAPP / myapp-web-api 文件夹,但不要主持。答案 0 :(得分:0)
之间的区别是什么?
docker-compose run
和docker run
???
不同之处在于docker-compose.yml文件的卷部分:
volumes:
- .:/myapp-web-api
此命令将主机目录。?挂载到/ myapp-web-api的容器中 如果容器图片中已存在路径
/myapp-web-api
,则./
装载覆盖但不会删除预先存在的内容。
docker-compose up
命令暂时覆盖Dockerfile /myapp-web-api
指令中指定的ADD
的内容。
这不是docker run -i -t myappwebapi_web /bin/bash
命令的情况,它不会挂载任何主机文件夹。