docker run -d -p 4567 xxxxThe result is success
Closed this issue · 10 comments
Dockerfile content
FROM ubuntu:18.04
LABEL MAINTAINER="214520626@qq.com"
ENV REFRESHED_AT 2019-01-08
RUN apt-get -qq update && apt-get -qq install ruby ruby-dev build-essential redis-tools
RUN gem install --no-rdoc --no-ri sinatra json redis
RUN mkdir -p /opt/webapp
EXPOSE 4567
CMD [ "/opt/webapp/bin/webapp" ]
when I look docker logs is fail
[docker@al_first sinatra]$ docker run -d -p 4567 --name webapp -v $PWD/webapp:/opt/webapp alzerot/sinatra
fdf09145e8ecea477c292dbd741430259410befd1026e23f6cf582fd7c66583c
[docker@al_first sinatra]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
97072c9adcde alzerot/nginx "nginx" 11 hours ago Up 11 hours 0.0.0.0:32768->80/tcp website
3ddccfbbf41c registry "/entrypoint.sh /e..." 22 hours ago Up 22 hours 0.0.0.0:5000->5000/tcp pensive_edison
[docker@al_first sinatra]$ docker logs webapp
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': /opt/webapp/lib/app.rb:16: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /opt/webapp/bin/webapp:5:in `<main>'
But I don't know how to solve it
This is my directory
[docker@al_first sinatra]$ ll
total 8
-rw-rw-r-- 1 docker docker 297 Jan 8 09:54 Dockerfile
drwxrwxr-x 4 docker docker 4096 Jan 7 23:12 webapp
[docker@al_first sinatra]$ cd webapp/
[docker@al_first webapp]$ ll
total 8
drwxrwxr-x 2 docker docker 4096 Jan 7 23:15 bin
drwxrwxr-x 2 docker docker 4096 Jan 7 23:15 lib
[docker@al_first webapp]$ cd bin/
[docker@al_first bin]$ ll
total 4
-rwxrwxr-x 1 docker docker 119 Jan 7 23:02 webapp
[docker@al_first bin]$ cd ..
[docker@al_first webapp]$ cd lib
[docker@al_first lib]$ ll
total 4
-rw-rw-r-- 1 docker docker 218 Jan 7 23:03 app.rb
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.