Closed AlZero-t closed 5 years ago
Can you paste in the contents of /opt/webapp/lib/app.rb
? Did you change it at all? That error looks like the code got edited.
Need me to go to the container to check the file? This is what I see on the host machine. I did not make any changes and copied them directly.
[docker@al_first lib]$ cat app.rb
require "rubygems"
require "sinatra"
require "json"
class App < Sinatra::Application
set :bind, '0.0.0.0'
get '/' do
"<h1>DockerBook Test Sinatra app</h1>"
end
post '/json/?' do
params.to_json
end
@AlZero-t You can't have copied it directly. You're missing an end
.
require "rubygems"
require "sinatra"
require "json"
class App < Sinatra::Application
set :bind, '0.0.0.0'
get '/' do
"<h1>DockerBook Test Sinatra app</h1>"
end
post '/json/?' do
params.to_json
end
end
yes .you are right ,I'm forgot end . I still have a question about docker run -d -p . Here I will report an error using $PWD. I chose the absolute path. How can I avoid it. $PWD format
[docker@al_first webapp]$ docker run -d -p 4567 --name webapp -v $PWD/webapp:/opt/webapp alzerot/sinatra
dc8d4713f83e8a391ebf6a9e7eb81c696a08b16d70ef011f64f6110555465e0c
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/opt/webapp/bin/webapp\": stat /opt/webapp/bin/webapp: no such file or directory".
Absolute path
[docker@al_first webapp]$ docker run -d -p 4567 --name webapp1 -v /home/docker/sinatra/webapp:/opt/webapp alzerot/sinatra
de0b00c9aa312f504c435ed8e809b52ef5f63a2d3cf65c6ed63cdc7bdf4de23d
[docker@al_first webapp]$ docker logs webapp1
[2019-01-09 02:15:32] INFO WEBrick 1.4.2
[2019-01-09 02:15:32] INFO ruby 2.5.1 (2018-03-29) [x86_64-linux-gnu]
== Sinatra (v2.0.5) has taken the stage on 4567 for development with backup from WEBrick
[2019-01-09 02:15:32] INFO WEBrick::HTTPServer#start: pid=1 port=4567
In the first command, what directory are you in? What does $PWD resolve to? Try in the directory above.
I am executing in this directory /home/docker/sinatra/webapp . Because I looked at the path on GitHub, I created the same path.
[docker@al_first webapp]$ ll total 16 drwxrwxr-x 2 docker docker 4096 Jan 8 14:04 bin -rw-rw-r-- 1 docker docker 296 Jan 9 10:11 Dockerfile drwxrwxr-x 2 docker docker 4096 Jan 9 10:09 lib drwxr-xr-x 2 root root 4096 Jan 8 14:05 webapp [docker@al_first webapp]$ pwd /home/docker/sinatra/webapp
hence try in the directory above - you're mapping:
/home/docker/sinatra/webapp/webapp
I try /home/docker/sinatra/webapp/webapp run .is fail [docker@al_first webapp]$ docker run -d -p 4567 --name webapp -v $PWD/webapp:/opt/webapp alzerot/sinatra 5403a3ab83c0ef7857a4ba999dccad72de3c46cb60620a41490b70d6c9914073 /usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/opt/webapp/bin/webapp\": stat /opt/webapp/bin/webapp: no such file or directory". [docker@al_first webapp]$ pwd /home/docker/sinatra/webapp/webapp
No.
cd /home/docker/sinatra
docker run -d -p 4567 --name webapp -v $PWD/webapp:/opt/webapp
Thank you very much, the problem is solved.
Dockerfile content
when I look docker logs is fail
But I don't know how to solve it This is my directory