Skip to content

Instantly share code, notes, and snippets.

@efleming969
Last active January 18, 2017 10:48
Show Gist options
  • Save efleming969/811517b9b2dfa419b440 to your computer and use it in GitHub Desktop.
Save efleming969/811517b9b2dfa419b440 to your computer and use it in GitHub Desktop.
Docker demo notes

general

docker run modes

  • foreground vs background (detached)
  • iteractive tty option

simple hello world

docker run ubuntu:14.04 echo 'hello world'
docker logs <uuid>

managing containers

docker ps          # show foreground containers
docker ps -a       # show all foreground and previously ran containers
docker rm <uuid>   # remove a container by it UUID

Building images interactive

work with linux interactively, then commit changes to an image (words: http://goo.gl/OCkmyy)

docker run -i -t ubuntu:14.04 /bin/bash

> apt-get update
> apt-get upgrade -y
> apt-get install -y curl
> curl https://raw.githubusercontent.com/eneko/data-repository/master/data/words.txt > words.txt
> cat words.txt

docker logs <uuid prev container>
docker commit -m 'curl some words.txt' <uuid prev container> <tagname>
docker run -i -t <tagname>:latest

Building images with Dockerfile

FROM ubuntu:14.04

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y curl

RUN \
  curl http://www-01.sil.org/linguistics/wordlists/english/wordlist/wordsEn.txt > words.txt \
  cat words.txt

CMD [ "/bin/bash" ]

mongodb container

start up a mongodb server on port 27017 with a name for linking purposes

docker run -d -p 27017:27017 --name mongodb dockerfile/mongodb

access mongo db from anoterh container using a link

docker run -it --link mongodb:mongodb dockerfile/mongodb bash -c 'mongo --host mongodb'

> db.testData.insert( { name:"foo" } )
> db.testData.insert( { name:"bar" } )
> db.testData.insert( { name:"foobar" } )
> show collections
> db.testData.find()
> db.testData.find({name:"foo"})
> db.testData.findOne()
> db.testData.find().limit(2)
> exit

docker run -it --name node -v "$(pwd)":/data --link mongodb:mongodb -w /data -p 8082:8082 node:latest bash

mongodb http interaction

docker run -d -p 27017:27017 -p 28017:28017 --name mongodb dockerfile/mongodb mongod --rest --httpinterface

http://localhost:28017/

misc

running postgres in the background with a name (for linking purposes)

docker run -d --name db training/postgres

tell debian to install things without asking

ENV DEBIAN_FRONTEND noninteractive

run a java container in foreground mode with the version switch

docker run dockerfile/java:oracle-java7 java -version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment