在这个官方文档中,它可以在yaml配置文件中运行命令:
http://kubernetes.io/v1.1/docs/user-guide/configuring-containers.html
apiVersion: v1
kind: Pod
metadata:
name: hello-world
spec: # specification of the pod’s contents
restartPolicy: Never
containers:
- name: hello
image: "ubuntu:14.04"
env:
- name: MESSAGE
value: "hello world"
command: ["/bin/sh","-c"]
args: ["/bin/echo \"${MESSAGE}\""]
Run Code Online (Sandbox Code Playgroud)
如果我想运行多个命令,该怎么办?
从Rails API,我发现ActiveJob可以retry_job间隔:
my_job_instance.enqueue
my_job_instance.enqueue wait: 5.minutes
my_job_instance.enqueue queue: :important
my_job_instance.enqueue wait_until: Date.tomorrow.midnight
Run Code Online (Sandbox Code Playgroud)
但是如果我想设置重试计数,比如Sidekiq:
include Sidekiq::Worker
sidekiq_options :retry => 5
Run Code Online (Sandbox Code Playgroud)
该示例代码怎么办?
class SiteScrapperJob < ActiveJob::Base
rescue_from(ErrorLoadingSite) do
retry_job queue: :low_priority
end
def perform(*args)
# raise ErrorLoadingSite if cannot scrape
end
end
Run Code Online (Sandbox Code Playgroud)
现在我把它添加到我的工作班:
Sidekiq.default_worker_options = { retry: 5 }
Run Code Online (Sandbox Code Playgroud)
但似乎不是很好.
我在最新的Mac OS上安装了vim by brew:
brew install vim
Run Code Online (Sandbox Code Playgroud)
当我输入时brew info vim
,它显示:
vim: stable 7.4.891, HEAD
Vi "workalike" with many additional features
http://www.vim.org/
Conflicts with: ex-vi
/usr/local/Cellar/vim/7.4.891 (1612 files, 28M) *
Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/vim.rb
...
Run Code Online (Sandbox Code Playgroud)
但如果键入vim
,它会显示我的7.3
版本为vim:
VIM - Vi IMproved
version 7.3
...
Run Code Online (Sandbox Code Playgroud)
我该如何使用该7.4
版本?
我正在使用rails,sidekiq和docker.
我的docker-compose.yml文件
sidekiq:
build: .
command: bundle exec sidekiq -C config/sidekiq.yml
links:
- db
- redis
Run Code Online (Sandbox Code Playgroud)
config/sidekiq.yml文件
:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
- default
Run Code Online (Sandbox Code Playgroud)
运行后docker-compose up
,sidekiq服务无法正常启动.
sidekiq_1 | No such file or directory @ rb_sysopen - /testapp/tmp/pids/sidekiq.pid
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/lib/sidekiq/cli.rb:365:in `initialize'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/lib/sidekiq/cli.rb:365:in `open'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/lib/sidekiq/cli.rb:365:in `write_pid'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/lib/sidekiq/cli.rb:42:in `parse'
sidekiq_1 | /usr/local/bundle/gems/sidekiq-3.5.3/bin/sidekiq:12:in `<top (required)>'
sidekiq_1 | /usr/local/bundle/bin/sidekiq:16:in `load'
sidekiq_1 | /usr/local/bundle/bin/sidekiq:16:in `<main>'
testapp_sidekiq_1 exited with code 1
Run Code Online (Sandbox Code Playgroud) 我创建了一个rails应用程序:testapp.
然后加入Dockerfile
和docker-compose.yml
其下的文件.
Dockerfile
FROM ruby:2.2.0
RUN apt-get update -qq && apt-get install -y build-essential mysql-client libmysqlclient-dev nodejs
RUN mkdir /testapp
WORKDIR /testapp
ADD Gemfile /testapp/Gemfile
ADD Gemfile.lock /testapp/Gemfile.lock
RUN bundle install
ADD . /testapp
Run Code Online (Sandbox Code Playgroud)
泊坞窗,compose.yml
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: 1234
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/testapp
ports:
- "3000:3000"
links:
- db
Run Code Online (Sandbox Code Playgroud)
我的数据库设置文件:
配置/ database.yml的
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: …
Run Code Online (Sandbox Code Playgroud) 我想使用docker来部署rails应用程序.我按照官方教程做了:
https://docs.docker.com/compose/rails/
但似乎我不幸运.
我的Dockerfile
FROM ruby:2.2.2
RUN apt-get update -qq && apt-get install -y build-essential
# for mysql
RUN apt-get install -y mysql-client libmysqlclient-dev
# for a JS runtime
RUN apt-get install -y nodejs
ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
ADD Gemfile $APP_HOME/Gemfile
ADD Gemfile.lock $APP_HOME/Gemfile.lock
RUN bundle install
ADD . $APP_HOME
Run Code Online (Sandbox Code Playgroud)
我的docker-compose.yml
db:
image: mysql
ports:
- "3306:3306"
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
links: …
Run Code Online (Sandbox Code Playgroud) 我创建了一个使用mysql数据库的Rails应用程序。现在想将它们放入docker容器中。我正在使用docker,docker-machine,docker-compose。
我的docker-compose.yml
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: <%= ENV['MYSQL_ROOT_PASSWORD'] %>
ports:
- "3306:3306"
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
links:
- db
Run Code Online (Sandbox Code Playgroud)
我的config / database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: <%= ENV['MYSQL_ROOT_PASSWORD'] %>
host: <%= ENV['DB_PORT_3306_TCP_ADDR'] %>
port: <%= ENV['DB_PORT_3306_TCP_PORT'] %>
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
production:
<<: *default
database: myapp_production
Run Code Online (Sandbox Code Playgroud)
启动应用程序时
$ docker-compose up
...
sidekiq_1 …
Run Code Online (Sandbox Code Playgroud) 我正在使用docker和rails.
我创建了一个本地gem并将其放入vendor/gems文件夹中.
我将它添加到我的Gemfile中:
gem 'my_gem', path: './vendor/gems/my_gem'
Run Code Online (Sandbox Code Playgroud)
在我的Dockerfile中
RUN mkdir /testapp
WORKDIR /testapp
ADD Gemfile /testapp/Gemfile
ADD Gemfile.lock /testapp/Gemfile.lock
RUN bundle install
ADD . /testapp
Run Code Online (Sandbox Code Playgroud)
运行后docker-compose build
,它显示:
The path `/testapp/vendor/gems/my_gem` does not exist.
ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 13
Run Code Online (Sandbox Code Playgroud)