2

My final goal is to start-up a docker container and move some files around in that docker container. Because this takes several commands, I want to write a script that does this automatically (as opposed to writing all these commands each time by hand). My plan here is to create a bash-script for this.

The problem starts right after the first command:

nvidia-docker run -it --name "Test" gcr.io/tensorflow/tensorflow:latest-gpu

This put the following output on screen (in the same GUI as the Ubuntu terminal I wrote the command in):

[I 14:42:36.484 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 14:42:36.509 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 14:42:36.513 NotebookApp] Serving notebooks from local directory: /notebooks
[I 14:42:36.513 NotebookApp] 0 active kernels 
[I 14:42:36.513 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=6731bf8e21c987cd142076cbeb77ed3cf0f97275bcdb7bce
[I 14:42:36.513 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 14:42:36.513 NotebookApp] 

Now I can 'exit' this by typing ctrl+C, which allows me to go 'back' to the original terminal (still, same GUI) and start typing Ubuntu terminal commands again. But how do I replicate this action in a script?

  • Does running exit work? – terdon Mar 7 '17 at 14:41
  • No, it doesn't give a response. Not even "echo hello world" gives a response. Only ctrl+C closes it after a confirmation (y/[n]) – dimpol Mar 7 '17 at 14:43
  • Does Ctrl+D also close it? Didn't you say you were in a prompt? Can you actually run commands? Also, do you want to exit and stop? Could you just kill the nvidia-docker process? – terdon Mar 7 '17 at 14:51
  • No, ctrl+D doesn't close it. I am beginning to suspect it is not a prompt I'm entering. GUI-wise, I'm not changing windows from my original Ubuntu terminal. The problem is that I don't want to stop the docker process, I just want to be able to enter a next command. – dimpol Mar 7 '17 at 14:58
  • Ah, better yes, thanks. That isn't a prompt. In fact, that looks like it just set up some sort of server/daemon which you can't interact with. How would you normally run the commands you want to run? You can't run them there, so where do you do it when doing it manually? All of this should be in your question. While a docker expert might be able to figure this out immediately, non-experts with general knowledge might also be able to help, but only if you provide enough detail. – terdon Mar 7 '17 at 15:31
2

I think what you're missing is the -d parameter to run it in the background

docker run -d --name "Test" gcr.io/tensorflow/tensorflow:latest-gpu

Doing that starts up the container without transferring you into it. So that way your script can continue to run other commands.

Now if you need to actually "move some files around" within the container, what you can do is mount your script as a volume and run it.

docker run -d -v$(pwd):/my --name Test gcr.io/tensorflow/tensorflow:latest-gpu bash 
docker exec -d Test bash /my/script.sh

So that way you mount your preset working directory into the container and then within the container run that script, while continuing along in your original script. so then add

docker exec -it Test bash

and now you are in your container, after having run the script.

or, you can just run several docker exec commands instead of mounting a folder.

#!/bin/bash
docker run  -d --name Test gcr.io/tensorflow/tensorflow:latest-gpu bash 
docker exec -d  Test bash cp /x /y
docker exec -d  Test bash cp /y /z
docker exec -it Test bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.