I am working on a nodejs twitter api and it’s working perfectly fine in the local env but when I try to containerize, it fails with a 401 error from twitter.js which is "HTTP 401 Unauthorized client error status response code".
Error
> node app.js
Error: Status Code: 401
at Request.<anonymous> (/usr/src/app/node_modules/twitter/lib/twitter.js:277:28)
at Request.emit (events.js:315:20)
at Request.onRequestResponse (/usr/src/app/node_modules/request/request.js:1059:10)
at ClientRequest.emit (events.js:315:20)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:603:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:117:17)
at TLSSocket.socketOnData (_http_client.js:472:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:273:9)
I did my search on this where I found that this could a time mismatch issue in the docker container. My docker container is running 1 and a half hours behind the actual time. I am not sure if this is the only issue.
My docker file
FROM node:13.13.0-alpine
# Create app directory
WORKDIR /usr/src/app
COPY package*.json ./
# Bundle app source
COPY . .
ENV KAFKA_HOST=localhost:9092
KAFKA_TOPIC=tweetstream
CMD ["npm", "start"]
How can I set the right time in this docker image?
2
Answers
I am on a Windows host machine and as I mentioned in the question there was a time difference between my host and the containers.
What I did to resolve the time difference?
I also feel you will have to redo it once your windows machine goes into hibernation.
Reference articles: https://thorsten-hans.com/docker-on-windows-fix-time-synchronization-issue
https://www.ivankrizsan.se/2015/10/31/time-in-docker-containers/
OAuth requires close time synchronisation, so that is very likely to be the issue, especially if your code works outside of the container in a system where the time is synchronised.