I want to run the ruby script that I made on windows on ruby container

Asked 1 years ago, Updated 1 years ago, 37 views

What do you want to do

Create a ruby container on windows with docker and run the ruby script you edited on windows.

Tried

  • Create a ruby container by defining the following ($docker-compose up-d)
version: '3'
services:
  rubyapp:
    image:ruby:2.5-alpine
    container_name —myruby
  • Prepare ruby scripts on windows (using git for Windows)
C:/home/docker/myapp/
|-- docker-compose.yml
`-- ruby
    `-- app
        `-- test.rb


$ echo "putsTime.now" > ruby/app/test.rb

Results

Run the following command

# Missing error with path on Windows
$ winty docker run-v "C:\home\docker\myapp\ruby\app": /root ruby: 2.5 -alpine ruby ruby/app/test.rb
ruby: No such file or directory -- ruby/app/test.rb (LoadError)


# Error specifying path on container
$ winty docker run-v "C:\home\docker\myapp\ruby\app": /root ruby: 2.5 -alpine ruby/root/test.rb
ruby: No such file or directory -- C:/Program Files/Git/root/test.rb (LoadError)


# -e option allows you to do it
$ winty docker run-v "C:\home\docker\myapp\ruby\app": /root ruby:2.5-alpine ruby-e "puts Time.now"
2018-12-17 05:47:23 +0000

I would appreciate it if you could let me know if the method of specifying the command is bad or not possible in the first place.
Thank you for your cooperation.

ruby docker

2022-09-30 16:33

1 Answers

If you just want to run ruby, you don't need to create docker-compose.yml.

The above command shows
I think it is an error because workdir is not configured.

$docker run --workdir=/app --volume="C:\home\docker\myapp\ruby\app":/app ruby:2.5-alpine ruby test.rb

Also, if you cannot find the file,
$docker run --workdir=/app --volume="C:\home\docker\myapp\ruby\app":/appruby:2.5-alpine/bin/sh
You may also want to go find the mounted file in


2022-09-30 16:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.