Skip to content

Commit

Permalink
Add docker image to grab the ip used by docker (eclipse-che#1891)
Browse files Browse the repository at this point in the history
Change-Id: Id781e34c99f14c87909197b99969d645268e62d3
Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
  • Loading branch information
benoitf authored and ShimonBenYair committed Aug 4, 2016
1 parent 4d0b45f commit 1af2045
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dockerfiles/che-ip/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2016 Codenvy, S.A.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# To build, in this directory:
# `docker build -t codenvy/che-ip .`
#
# To use it:
# `docker run --rm --net=host codenvy/che-ip`

FROM alpine:3.4

ADD getip.sh /bin/getip.sh

CMD /bin/getip.sh
29 changes: 29 additions & 0 deletions dockerfiles/che-ip/getip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh
# Copyright (c) 2012-2016 Codenvy, S.A., Red Hat, Inc
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html


# return true if system is using boot2docker
is_boot2docker() {
if uname -r | grep -q 'boot2docker'; then
return 0
else
return 1
fi
}

# network interface to use to grab local ip
NETWORK_IF="eth0"
if is_boot2docker; then
NETWORK_IF="eth1"
fi

# grab ip from the following command
ip a show "${NETWORK_IF}" | \
grep 'inet ' | \
cut -d/ -f1 | \
awk '{print $2}'

0 comments on commit 1af2045

Please sign in to comment.