Skip to content

Instantly share code, notes, and snippets.

@mnguyenngo
Last active August 24, 2018 21:11
Show Gist options
  • Save mnguyenngo/1d1c51545c74e6be270e089582f58f54 to your computer and use it in GitHub Desktop.
Save mnguyenngo/1d1c51545c74e6be270e089582f58f54 to your computer and use it in GitHub Desktop.
Typical workflow for creating a Docker image and pushing the image to docker hub
"""simple Dockerfile
FROM alpine:3.1 # starter image (typical)
MAINTAINER <name> <email>
ADD hello /usr/bin/hello # ADD <bin> <path-on-image>
ENTRYPOINT ["hello"] # run hello app on startup
"""
# install GO
wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz
rm -rf /usr/local/bin/go
sudo tar -C /usr/local -xzf go1.6.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
export GOPATH=~/go
# install git if not installed already
sudo apt-get install git-core
# get the app code
mkdir -p $GOPATH/src/github.com/udacity
cd $GOPATH/src/github.com/udacity
git clone https://github.com/udacity/ud615.git
# build a static binary of the monolith app
cd ud615/app/monolith
go get -u
go build --tags netgo --ldflags '-extldflags "-lm -lstdc++ -static"'
# the commands above did not work the first time; delete and reclone the repo and try again
# create a container for the app
# build the app container
sudo docker build -t monolith:1.0.0 .
# list the monolith image
sudo docker images monolith:1.0.0
# run the monolith container and get it's IP
sudo docker run -d monolith:1.0.0
sudo docker ps # copy the container id
sudo docker inspect <container name or cid> # copy the IP address
curl <the container IP>
# optional: set the container ids and IPs to variables
CID=$(sudo docker run -d monolith:1.0.0)
CIP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID})
curl $CIP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment