HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashMinor

Pulling Docker Machine IP

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
dockerpullingmachine

Problem

I am working with MongoDB through Docker, and I have a terrible bash command to pull the Docker Machine IP so I can sanely connect locally.

export dockerip="$(docker-machine ls | awk '{print $5}' | sed -n '2p' | sed 's/tcp:\/\///' | sed 's/\:2376//')"
mongo --host "$dockerip" --port 27017


How can I optimise the docker-machine line?

Solution

docker-machine provides a simple way to get the IP of the host machine

mongo --host `docker-machine ip default` --port 27017


I'm using default here, since that's the name of the machine I'm using.

Code Snippets

mongo --host `docker-machine ip default` --port 27017

Context

StackExchange Code Review Q#104937, answer score: 5

Revisions (0)

No revisions yet.