Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker run... enter container... then every command gets "ReferenceError: <command> is not defined"

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!

like image 866
Kevin Danikowski Avatar asked Aug 20 '17 20:08

Kevin Danikowski


2 Answers

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).

like image 130
johnharris85 Avatar answered Oct 12 '22 13:10

johnharris85


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
like image 27
sauerburger Avatar answered Oct 12 '22 13:10

sauerburger