1

I’m setting up a basic docker container which contains a server.js script inside my-app folder.

My dockerfile looks like this:

#Use node parent image
FROM node:9.6.1

#Set the working directory to /my-app
WORKDIR /my-app


# Make port 80 available to the world outside this container
EXPOSE 80


cmd pwd
RUN npm install


# start app
CMD node server.js

The server.js file is not found and I'm trying to debug this by printing pwd to the terminal. I get the error when server.js file cannot be found, but CMD pwd seems to be ignored. How can I print in the container to find out why server.js cannot be executed?

Vincent
  • 6,058
  • 15
  • 52
  • 94
  • I do not understand this Line `cmd pwd` – user2915097 Jul 06 '18 at 13:56
  • Also your WORKDIR /my-app needs that folder already created... – user2915097 Jul 06 '18 at 13:58
  • cmd pwd is to get the path where the next cmd commend will be executed – Vincent Jul 06 '18 at 14:00
  • CMD doesn't produce any output. See https://stackoverflow.com/questions/37461868/whats-the-difference-between-run-and-cmd-in-a-docker-file-and-when-should-i-use/37462208#37462208 – David Maze Jul 06 '18 at 14:10
  • Possibly related: https://stackoverflow.com/questions/46356999/how-to-redirect-stdout-from-docker-container-to-host and https://stackoverflow.com/questions/34632959/redirecting-command-output-in-docker. The second one seems to be a solution you'd be interested in. –  Jul 06 '18 at 14:15

2 Answers2

0

You can use docker run yourcontainername to start your container (if it is stopped) to see what goes wrong.

If your container keeps running (which it probably doesn't) you can go into the container using docker exec -it yourcontainername bash and figure out what goes wrong.

ps: you are probably missing the following in your Dockerfile: COPY server.js /my-app/

Lazykiddy
  • 1,525
  • 1
  • 11
  • 18
  • The thing is that Dockerfiles should normally only have one CMD command. (because Docker containers should only manage 1 process) You could add something like `RUN echo $HOME` in the Dockerfile, then build it. During building you will get the output that pwd would otherwise give you. – Lazykiddy Jul 06 '18 at 14:19
0

Change Dockerfile to:

FROM node:9.6.1
RUN mkdir -p /my-app
WORKDIR /my-app
COPY . /my-app
RUN npm install
EXPOSE 80
CMD node server.js
D. Vinson
  • 1,090
  • 6
  • 8