6

This has happened with multiple command variations. Basically... First I run the container: docker run -it --publish 8080:8080 --name app_in_docker node:latest

Then I have this response in the next line after a couple seconds: > This make it appear that I'm in the container, even though the command line usually looks like: root@bcb5705c09c1:/# when I'm in the container. Anything I type into this > however shows this:

ReferenceError: <command> is not defined
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:440:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)
    at REPLServer.Interface._onLine (readline.js:279:10)
    at REPLServer.Interface._line (readline.js:626:8)

I've used commands such as ls, cd, exit, help, --help, WORKDIR, docker, error, etc. without any success, I get the same message.

Then I just close docker quickstart terminal (I'm using windows and virtualbox runs in background) and reopen the terminal. I can now go into the container using: docker exec -it <container_name/id> bash and the command line now looks like it should: root@bcb5705c09c1:/#

Second semi-related question if you could help! How do I specify the volume path in my computer? I've unsuccessfully incorporated volume like so: docker run -it -v /c/app:/usr/src/app --publish 8080:8080 --name app_in_docker node:latest with the attempt to connect to files in C:\app folder. Might this be because I'm running virtualbox on windows?

Thank you for any help!

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75

2 Answers2

15

Not a node guy at all, but if you look at the node:latest Dockerfile you'll see that the default CMD that is executed is "node". So I guess you're being dropped into some kind of Node REPL where those shell commands won't work. Which is also why exec ... bash does work, you're in bash, not node.

If you want that behaviour the first time, just put bash at the end of your docker run ... command and it will override the default defined in the Dockerfile.

Second question, yes it's likely because you're running in Virtualbox on Windows. Is it just a regular setup? Or Docker-Machine (which mounts some host folders for you) or Docker for Windows (which is a different kettle of fish again).

johnharris85
  • 17,264
  • 5
  • 48
  • 52
  • I believe it may have been in the node command, but I noticed that when I got rid of -it it ran fine, I had thought i tried that ahead of time. It was a regular setup with docker-machine so it should have hosted some for me. I have been attempting to get into the settings to "share" the C drive, but I don't have the docker icon in the corner for some reason. – Kevin Danikowski Aug 20 '17 at 22:02
3

When you run the default command of the node image, docker starts the interactive node interpreter inside the container. The > prompt is the default prompt of node. Your command is equivalent to

docker run -it --publish 8080:8080 --name app_in_docker node:latest node

If you want to use commands like ls or cd inside the node image, you should start bash inside the container.

docker run -it --publish 8080:8080 --name app_in_docker node:latest bash
sauerburger
  • 4,569
  • 4
  • 31
  • 42
  • I just wrote bash at the end of it and it put me into the bash command, you are correct! Didn't think of that, I believe John was referencing that as well – Kevin Danikowski Aug 20 '17 at 22:04