将参数传递给docker run命令

时间:2017-07-24 22:33:35

标签: docker jekyll

我正在运行以下命令以使用我在本地检出的基于Jekyll的站点启动Jekyll:

docker run -p 4000:4000 --volume=$PWD:/srv/jekyll \ 
-it jekyll/jekyll:$JEKYLL_VERSION jekyll serve

这很好用。但是,当我将--baseurl参数传递给它时:

docker run -p 4000:4000 --volume=$PWD:/srv/jekyll \ 
-it jekyll/jekyll:$JEKYLL_VERSION jekyll serve --baseurl ''

一切都运行良好,直到达到这一点:

> docker run -p 4000:4000 --volume=$PWD:/srv/jekyll -it jekyll/jekyll:$JEKYLL_VERSION jekyll serve --baseurl ''
Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.15.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
The following gems are missing
 * jekyll (3.5.0)
Install missing gems with `bundle install`
Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.15.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Using public_suffix 2.0.5
Using bundler 1.15.2
Using colorator 1.1.0
Using ffi 1.9.18
Using forwardable-extended 2.6.0
Using rb-fsevent 0.10.2
Using kramdown 1.14.0
Using liquid 4.0.0
Using mercenary 0.3.6
Using rouge 1.11.1
Using safe_yaml 1.0.4
Using jekyll-paginate 1.1.0
Using addressable 2.5.1
Using rb-inotify 0.9.10
Using pathutil 0.14.0
Using sass-listen 4.0.0
Using listen 3.0.8
Using sass 3.5.1
Using jekyll-watch 1.5.0
Using jekyll-sass-converter 1.5.0
Fetching jekyll 3.5.0
Installing jekyll 3.5.0
Using jekyll-feed 0.9.2
Bundle complete! 3 Gemfile dependencies, 22 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
The latest bundler is 1.15.3, but you are currently running 1.15.2.
To update, run `gem install bundler`
/usr/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:31:in `go': missing argument: --baseurl (OptionParser::MissingArgument)
    from /usr/lib/ruby/gems/2.3.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
    from /usr/lib/ruby/gems/2.3.0/gems/jekyll-3.5.0/exe/jekyll:13:in `<top (required)>'
    from /usr/bin/jekyll:22:in `load'
    from /usr/bin/jekyll:22:in `<main>'

为什么会发生这种情况,如何将--basepath参数传递给jekyll命令?好像我正在使用docker做错了,我是新手。

谢谢!

1 个答案:

答案 0 :(得分:0)

根据https://docs.docker.com/v1.7/reference/run/#env-environment-variables处的文档,您可以使用带有-e参数的docker run命令传递它。

这是我在一个简单的运行脚本中测试的:

# Start Jekyll and watch for changes
docker run --rm -it \
    -e JEKYLL_ENV=production \
    --volume=/$(pwd):/srv/jekyll \
    --publish 4000:4000 \
    $DOCKER_IMAGE_NAME

图像简直就是grahamc / jekyll。我尝试添加-e BASEURL =&#34;&#34; \到上面的docker run命令。但是我发现如果在_config.yml中设置了baseurl,那么该设置将胜过环境设置。

相关问题