Note that there are some explanatory texts on larger screens.

plurals
  1. POBash Script to execute Docker container operations and extract container IP Address
    primarykey
    data
    text
    <p>I am trying to write a Linux bash script that creates and runs docker containers that run a simple python web server, extract the container IP Address and make an HTTP Request to the server through a browser. There seem to be some mistakes in my script and I need help in editing it. I am new to bash scripting. I use Ubuntu 13.10</p> <p>My Script:</p> <pre><code>#!/bin/bash for i in {1..2} do echo "Creating and Running Container $i " sudo docker run -name $i PythonServer IP=sudo docker inspect $i | grep IPAddress | cut -d '"' -f 4 echo "Ip Address is:" echo "${IP}" xdg-open 'http://$IP:7111/execute' done </code></pre> <p>EDIT: Line 6 of the code doesn't seem to be working as <code>echo "${IP}"</code> is giving a blank output. I want to assign the result of <code>sudo docker inspect $i | grep IPAddress | cut -d '"' -f 4</code> to <code>IP</code> variable i.e I want to capture the IP Address of the created container and use it in <code>xdg-open 'http://$IP:7111/execute'</code> to make the HTTP Request dynamically. But I'm not getting the right format in which this bash script line should be written: <code>IP=sudo docker inspect $i | grep IPAddress | cut -d '"' -f 4</code> </p> <p>And also what is the correct format in which I can use <code>IP</code> value in <code>xdg-open 'http://$IP:7111/execute'</code></p> <p>This above mentioned script presently shows this message on execution:</p> <pre><code>vishal@bl-lin-01:~/docker/PythonServer/new$ ./BashScript.sh Creating and Running Container 1 WARNING: Docker detected local DNS server on resolv.conf. Using default external servers: [8.8.8.8 8.8.4.4] ^Cserving at port 7111 Traceback (most recent call last): File "/scripts/InitScript.py", line 40, in &lt;module&gt; httpd.serve_forever() File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever r, w, e = select.select([self], [], [], poll_interval) KeyboardInterrupt unknown option: 1 valid options are: -license -copyright -crlf -end -link -path_name -tab -ascii -apple_macro -assert_macro -minmax -unnamed default is all checks on; otherwise options specify desired checks Ip Address is: </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload