简体   繁体   中英

Writing a Bash Script to Get the Token of a Jupyter Notebook Running in a Container

I run a Dockerized Jupyter Server and I don't want to retrieve its access token manually. So I'd like to write a bash script which will extract the token and open the server with it

I tried as follows:

docker run --name notebook -w /home/fenics -v $(pwd):/home/fenics/shared -d -p 127.0.0.1:8888:8888 quay.io/fenicsproject/stable 'jupyter-notebook --ip=0.0.0.0'
token=`docker logs notebook 2>&1 | grep -o "token=[a-z0-9]*" | sed -n 1p`
google-chrome http://127.0.0.1:8888/?$token

However, it doesn't work. Since the command docker logs notebook doesn't output anything if written in a script or in console on the same line with the command prior to it. But it does, if you write the commands in terminal one by one. Please, show me how the problem can be cast (it would be OK even if your solution is different) and explain why my code can't work (I do want to know because it is already the second problem I am trying to solve in this way)

Don't use `` but $() instead. I assume the shell might be different.

I just tried and it worked

token=$(docker logs notebook 2>&1 | grep -o "token=[a-z0-9]*"| sed -n 1p)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM