deeejay

Docker - Dockerfile Guide

Dec 17th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #Ubuntu based Hello World container
  2. #This is the base OS and version to use
  3. FROM ubuntu:15.04
  4.  
  5. #This is the creator of the Dockerfile
  6. MAINTAINER [email protected]
  7.  
  8. #Updates the repository
  9. #Use RUN commands to run commands against our images that we're building
  10. #Every RUN command adds a new layer
  11. #Launches container and runs apt-get update and stops container
  12. RUN apt-get update
  13. #Launches container and runs apt-get install nginx and stops container
  14. RUN apt-get install -y nginx
  15. #Launches container and runs apt-get install golang and stops container
  16. RUN apt-get install -y golang
  17.  
  18. #instead combine multiple RUN commands into one long command
  19.  
  20. #Example
  21. CMD ["echo","Hello World"]
  22.  
  23.  
  24. #Important! Save this file as "Dockerfile" with a capitale "D" only
  25.  
  26. #To Build - run this command and name it helloworld as version 0.1 using the Dockerfile in this current directory
  27. #Note: -t is an image tag
  28. docker build -t helloworld:0.1 .
  29.  
  30. docker build -t="build1" .
  31.  
  32.  
  33. #Diving Deeper into Dockerfile
  34. #Build cache
  35.  
  36.  
  37.  
  38.  
  39. #Simple web server
  40. FROM ubuntu:15.04
  41. RUN apt-get udpate
  42. RUN apt-get install -y apache2
  43. RUN apt-get install -y apache2-utils
  44. RUN apt-get install -y vim
  45. RUn apt-get clean
  46. EXPOSE 80
  47. CMD ["apache2ctl", "-D", "FOREGROUND"]
  48. #end Dockerfile
  49.  
  50. #build web server
  51. docker build -t="webserver" .
  52.  
  53. #view docker images
  54. docker images
  55.  
  56. #Run container and map port 80 in docker to 80 on host
  57. docker run -d -p 80:80 webserver
  58.  
  59. #Stop webserver
  60. docker stop dockername
Advertisement
Add Comment
Please, Sign In to add comment