├── .gitignore
├── README.md
├── Vagrantfile
├── code
├── hello.go
├── webapp.go
└── writedata.go
├── dockerfile
├── Dockerfile
└── hello
├── install-docker.sh
├── networking
├── Dockerfile
└── webapp
├── portmapping
├── Dockerfile
└── webapp
├── tagging
└── Dockerfile
└── volumes
├── Dockerfile
└── writedata
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .vagrant
3 | audio
4 | videos
5 | *.pptx
6 | uploader.yaml
7 | docker_slides
8 | capstone
9 | security/*
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # introduction_to_docker
2 |
3 | The code for the lessons is under the /code directory.
4 |
5 | To follow along with the lessons that require additional assets, check out the dockerfile, networking, portmapping, tagging, and volumes directories.
6 |
7 |
--------------------------------------------------------------------------------
/Vagrantfile:
--------------------------------------------------------------------------------
1 | # -*- mode: ruby -*-
2 | # vi: set ft=ruby :
3 |
4 | Vagrant.configure("2") do |config|
5 | # Every Vagrant development environment requires a box. You can search for
6 | # boxes at https://atlas.hashicorp.com/search.
7 | config.vm.box = "centos/7"
8 | end
9 |
--------------------------------------------------------------------------------
/code/hello.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | fmt.Println("Hello World! :D")
7 | }
8 |
9 | // Build with the following command from the same dir as this file.
10 | // env GOARCH=386 GOOS=linux go build hello.go
11 |
--------------------------------------------------------------------------------
/code/webapp.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "os"
7 | )
8 |
9 | func hostHandler(w http.ResponseWriter, r *http.Request) {
10 | name, err := os.Hostname()
11 |
12 | if err != nil {
13 | panic(err)
14 | }
15 |
16 | fmt.Fprintf(w, "
HOSTNAME: %s
", name)
17 | fmt.Fprintf(w, "ENVIRONMENT VARS:
")
18 | fmt.Fprintf(w, "")
19 |
20 | for _, evar := range os.Environ() {
21 | fmt.Fprintf(w, "- %s
", evar)
22 | }
23 | fmt.Fprintf(w, "
")
24 | }
25 |
26 | func rootHandler(w http.ResponseWriter, r *http.Request) {
27 |
28 | fmt.Fprintf(w, "Awesome site in Go!
")
29 | fmt.Fprintf(w, "Host info
")
30 | }
31 |
32 | func main() {
33 | http.HandleFunc("/", rootHandler)
34 | http.HandleFunc("/host/", hostHandler)
35 | http.ListenAndServe(":8080", nil)
36 | }
37 |
38 | // Compile with:
39 | // env GOARCH=386 GOOS=linux go build webapp.go
40 |
--------------------------------------------------------------------------------
/code/writedata.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | "time"
7 | )
8 |
9 | func main() {
10 |
11 | if len(os.Args) <= 1 {
12 | fmt.Println("Usage: writedata /path/to/file")
13 | panic("You're missing the file name")
14 | }
15 | filename := os.Args[1]
16 | hostname, err := os.Hostname()
17 |
18 | if err != nil {
19 | panic("Cannot determine the hostname.")
20 | }
21 |
22 | f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
23 | defer f.Close()
24 |
25 | for i := 0; i < 50; i++ {
26 | data := fmt.Sprintf("Host: %s - Loop Number: %d\n", hostname, i)
27 |
28 | _, err := f.WriteString(data)
29 | if err != nil {
30 | panic("Cannot write to file")
31 | }
32 | time.Sleep(time.Second)
33 | }
34 | }
35 |
36 | // Compile with:
37 | // env GOARCH=386 GOOS=linux go build writedata.go
38 |
--------------------------------------------------------------------------------
/dockerfile/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM scratch
2 | COPY hello /
3 | CMD ["/hello"]
--------------------------------------------------------------------------------
/dockerfile/hello:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudacademy/introduction_to_docker/3e2b08b8d9bbfa8ab91ec7b371bc4db59c0f870b/dockerfile/hello
--------------------------------------------------------------------------------
/install-docker.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | sudo yum remove docker docker-common docker-selinux docker-engine
4 |
5 | sudo yum install -y yum-utils device-mapper-persistent-data lvm2
6 |
7 | sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
8 |
9 | sudo yum install docker-ce
10 |
11 | sudo systemctl start docker
12 |
13 | sudo docker run hello-world
--------------------------------------------------------------------------------
/networking/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:16.04
2 |
3 | RUN apt update && apt install -y \
4 | arp-scan \
5 | iputils-ping \
6 | iproute2 \
7 | curl
8 |
9 | COPY webapp /
10 |
11 | CMD ["/bin/bash"]
12 |
13 | # This container is used for the networking demo
14 | # arp-scan --interface=eth0 --localnet
--------------------------------------------------------------------------------
/networking/webapp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudacademy/introduction_to_docker/3e2b08b8d9bbfa8ab91ec7b371bc4db59c0f870b/networking/webapp
--------------------------------------------------------------------------------
/portmapping/Dockerfile:
--------------------------------------------------------------------------------
1 | # Since we're using scratch we could omit this
2 | # scratch is the default base.
3 | FROM scratch
4 |
5 | # Copy the webapp binary from the current dir to the root of the container
6 | COPY webapp /
7 |
8 | # Expose is more documentation than anything else.
9 | EXPOSE 8080
10 |
11 | # The default command to run when starting the container
12 | CMD ["/webapp"]
--------------------------------------------------------------------------------
/portmapping/webapp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudacademy/introduction_to_docker/3e2b08b8d9bbfa8ab91ec7b371bc4db59c0f870b/portmapping/webapp
--------------------------------------------------------------------------------
/tagging/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:16.04
2 |
3 | RUN mkdir -p /demo && \
4 | echo "Version 1" > /demo/message
5 |
6 | CMD ["/bin/cat", "/demo/message"]
7 |
--------------------------------------------------------------------------------
/volumes/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM scratch
2 | COPY writedata /
3 | CMD ["/writedata", "/logs/myapp"]
--------------------------------------------------------------------------------
/volumes/writedata:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudacademy/introduction_to_docker/3e2b08b8d9bbfa8ab91ec7b371bc4db59c0f870b/volumes/writedata
--------------------------------------------------------------------------------