Error building a Docker image

I’m new to Dockers so I’m trying to figure out how everything works. I’ve got a Rails app and I’m having issue’s.
I’m trying to build a Docker image with Ruby 2.2.4. I’m getting an error:

Your Ruby version is 2.3.1, but your Gemfile specified 2.2.4
The command '/bin/sh -c bundle install' returned a non-zero code: 18

Why is it happing and what to do to solve the problem?