I am following this tutorial for service discovery http://jasonwilder.com/blog/2014/07/15/docker-service-discovery
Briefly:
I created an etcd host running at x.y.z.d:4001
docker run -d --name etcd -p 4001:4001 -p 7001:7001 coreos/etcd
Created a backend server running a container at backend_serverip:8000 and docker-register
$ docker run -d -p 8000:8000 --name whoami -t jwilder/whoami
$ docker run --name docker-register -d -e HOST_IP=$(hostname --all-ip-addresses | awk '{print $1}') -e ETCD_HOST=x.y.z.d:4001 -v /var/run/docker.sock:/var/run/docker.sock -t jwilder/docker-register
Created another backend server running a container at backend2_serverip:8000 and docker-register
$ docker run -d -p 8000:8000 --name whoami -t jwilder/whoami
$ docker run --name docker-register -d -e HOST_IP=$(hostname --all-ip-addresses | awk '{print $1}') -e ETCD_HOST=x.y.z.d:4001 -v /var/run/docker.sock:/var/run/docker.sock -t jwilder/docker-register
Created a client running docker-discover and an ubuntu image
$ docker run -d --net host --name docker-discover -e ETCD_HOST=10.170.71.226:4001 -p 127.0.0.1:1936:1936 -t jwilder/docker-discover
When I look at the logs to see if containers are being registered I see teh folowing error
2015/07/09 19:28:00 error running notify command: python /tmp/register.py, exit status 1
2015/07/09 19:28:00 Traceback (most recent call last):
File "/tmp/register.py", line 22, in <module>
backends = client.read("/backends")
File "/usr/local/lib/python2.7/dist-packages/etcd/client.py", line 347, in read
self.key_endpoint + key, self._MGET, params=params, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/etcd/client.py", line 587, in api_execute
return self._handle_server_response(response)
File "/usr/local/lib/python2.7/dist-packages/etcd/client.py", line 603, in _handle_ser
etcd.EtcdError.handle(**r)
File "/usr/local/lib/python2.7/dist-packages/etcd/__init__.py", line 184, in handle
raise exc(msg, payload)
etcd.EtcdKeyNotFound: Key not found : /backends
I tried manually creating this directory , I also tried running the containers with privileged option but no luck
The error you are getting is from a bug in the code. The problem is that /backends does not exist in your etcd directory. You can create it yourself by manually by running this:
curl -L http://127.0.0.1:4001/v2/keys/backends -XPUT -d dir=true
Once the directory exists in etcd, you won't get the error anymore.
I created a pull request that fixes the bug and if you want to use the fixed code, you can build your own image:
git clone git#github.com:rca/docker-register.git
cd docker-register
docker build -t docker-register .
Then your command for docker register would look like:
$ docker run --name docker-register -d -e HOST_IP=$(hostname --all-ip-addresses | awk '{print $1}') -e ETCD_HOST=x.y.z.d:4001 -v /var/run/docker.sock:/var/run/docker.sock -t docker-register
Note I simply removed jwilder/ from the image name in the command so it uses your local version.
Related
I have a Docker image named pfa-image (contains a fairly basic Express-based website), a running mongoDB container named pfa-mongo, and a docker volume named image-volume. When I run the following sequence of commands..:
host$ docker run -d --name pfa-container -v image-volume:/images \
--link pfa-mongo:mongodb -p 5000:5000 pfa-image
host$ docker exec -it pfa-container /bin/bash
container:/pfa-site# cd images
container:/pfa-site/images# touch test.txt
container:/pfa-site/images# exit
host$ docker rm -f pfa-container
host$ docker run -d --name pfa-container -v image-volume:/images \
--link pfa-mongo:mongodb -p 5000:5000 pfa-image
host$ docker exec -it pfa-container /bin/bash
container:/pfa-site# cd images
container:/pfa-site/images# ls
...test.txt is missing. What am I overlooking here? I am quite new to docker and somewhat new to Linux.
Thank you!
I have tried using bind mounts and volumes, to the same result.
Working on docker desktop on windows.
docker command from the PowerShell:
docker run -p 80:8080 -d --name demo1 -e SWAGGER_JSON=/custom/swagger.json -v a-data-volume:/custom swaggerapi/swagger-ui
docker command from the Git Bash:
docker run -p 80:8080 -d --name demo2 -e SWAGGER_JSON=/custom/swagger.json -v a-data-volume:/custom swaggerapi/swagger-ui
Issue: The environment variable SWAGGER_JSON is not the same on both containers even though it is set the same way in the command. While demo1 has the correct one, demo2 doesn't.
I'm using Docker for Windows:
Docker version 18.03.1-ce-win64
Docker Engine 18.03.1-ce
ClickHouse client version 1.1.54380
ClickHouse server version 1.1.54380
For exporting data from table into CSV format I am using the command:
Now run clickhouse-client container for export
$ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --query="select * from default.table1 FORMAT CSV" > C:/Users/sony/Desktop/table1_data.csv --host clickhouse-server
NOTE: The above command works perfectly.
Now run clickhouse-client container for import
$ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m -c "cat C:/Users/sony/Desktop/table1_data.csv | clickhouse-client --host clickhouse-server --query='INSERT INTO default.table1 FORMAT CSV' "
Could you please tell me what I am doing wrong when importing?
Thanks in advance.
I think you should mount the csv file inside the container first. To mount the file you should add -v C:/Users/sony/Desktop/table1_data.csv :~/table1_data.csv option on your docker command. So your docker run command should be like this:
$ docker run -it --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m -v C:/Users/sony/Desktop/table1_data.csv:~/table1_data.csv -c "cat ~/table1_data.csv | clickhouse-client --host clickhouse-server --query='INSERT INTO default.table1 FORMAT CSV'"
Edit
My bad. Mounting inside the file wont work. Try this instead:
cat path_to_file/table1_data.csv | docker run -i --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --host clickhouse-server --query="INSERT INTO default.table1 FORMAT CSV"
Already tried on linux, and it works. Since cat not works on Windows, I found type has same functionality, honestly haven't try it:
`type C:/Users/sony/Desktop/table1_data.csv | docker run -i --rm --link clickhouse-server:clickhouse-client yandex/clickhouse-client -m --host clickhouse-server --query="INSERT INTO default.table1 FORMAT CSV"`
Hope it works.
I am running solr in docker and I tried the commands from the comment.
docker run --name test -d -p 8983:8983 -t solr
docker exec -it --user=solr test bin/solr create -c techproducts -d sample_techproducts_configs
After the last command, I received the following error message:
Unrecognized argument: example/exampledocs/*.xml .
If this was intended to be a data file, it does not exist relative to /opt/solr
Is this the correct location for the techproducts.xml data?
I looked at the official solr image on hub.docker.com and I found this,
docker run -d -P -v $PWD/myconfig:/myconfig solr solr-create -c mycore -d /myconfig
I guess you need to pass in core configuration from your host with bind mount as in the example. In this case it is not myconfig, it is "sample_techproducts_configs"
I tried the following, it worked for me.
docker run --name my_solr -d -p 8983:8983 -t solr
docker exec -it --user=solr my_solr bin/solr create_core -c
techproducts
docker exec -it --user=solr my_solr bin/post -c techproducts
example/exampledocs/
How can I separate a database and rails app into two different containers? The tutorial on Docker shows how to create the two with the docker-compose set-up, however I'm more curious on how to set this up manually so that I can play around with SOA on Docker.
Create an instance of your db container
db stop/rm/pull/run:
# First three lines are for teardown/reubuild
#!/bin/bash
docker stop myapp-postgres
docker rm myapp-postgres
docker pull postgres
docker run --name myapp-postgres -t -i -d postgres
app stop/rm/pull/run:
#!/bin/bash
docker stop myapp
docker rm myapp
docker pull dockerhubname/myapp
docker run -d -t -i --link myapp-postgres:postgres -p 80:80 --name myapp dockerhubname/myapp
#spit out some useful info
docker ps
MYAPP_MACHINE=$(docker ps | grep myapp | awk '{print $1}')
echo $MYAPP_MACHINE
docker exec -ti $MYAPP_MACHINE ps -aux