Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker image to grab the ip used by docker #1891

Merged
merged 1 commit into from
Jul 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}'