I have another data source that gives me the weight(speed or time) of each segment(node to node).
Are you sure? Graphhopper ‘segments’ (=edges) are not the same as the OSM ways.
I prefer not to change the code because I’m using a docker image, but if I have to change the code, what should I do?
This is not implemented in the default distribution, so yes you need to write some code for this yourself. You probably want to load the file when the server starts and add your own implementation of the Weighting interface to the weighting factory that returns the speeds from the file.