Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Last active January 14, 2017 14:12
Show Gist options
  • Save md2perpe/2639afcd79e359a857ef94ba7908fb80 to your computer and use it in GitHub Desktop.
Save md2perpe/2639afcd79e359a857ef94ba7908fb80 to your computer and use it in GitHub Desktop.

Works

$ docker run -d -P --name test_sshd rastasheep/ubuntu-sshd:14.04

$ docker ps
CONTAINER ID        IMAGE                          COMMAND               CREATED             STATUS              PORTS                   NAMES
04696512ed29        rastasheep/ubuntu-sshd:14.04   "/usr/sbin/sshd -D"   21 hours ago        Up 3 seconds        0.0.0.0:32779->22/tcp   test_sshd

$ ssh -p 32779 root@localhost
The authenticity of host '[localhost]:32784 ([::1]:32784)' can't be established.
ECDSA key fingerprint is SHA256:aWOGNAnVf9xZ+h8SePO8sybhitLNcp70ZbjsGkNMvpg.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:32784' (ECDSA) to the list of known hosts.
root@localhost's password:
root@33b7800d633e:~#

Doesn't work

$ ls
Dockerfile  main.go

$ docker build -t test-app .
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM golang:1.6-onbuild
# Executing 3 build triggers...
Step 1 : COPY . /go/src/app
 ---> Using cache
Step 1 : RUN go-wrapper download
 ---> Using cache
Step 1 : RUN go-wrapper install
 ---> Using cache
 ---> cc72239163b9
Step 2 : EXPOSE 80
 ---> Using cache
 ---> 1d6ab44cd4ae
Step 3 : CMD app
 ---> Using cache
 ---> 8d9c4e57e86e
Successfully built 8d9c4e57e86e
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

$ docker run -d -P --name test_app test-app
abea7ffbabb6a9750552d7188168cd7d6aa8636ee3cd1c67a30ee606a93e3626

$ docker ps
CONTAINER ID        IMAGE                          COMMAND               CREATED             STATUS              PORTS                   NAMES
abea7ffbabb6        test-app                       "app"                 20 hours ago        Up 16 seconds       0.0.0.0:32786->80/tcp   test_app

$ curl -sv http://localhost:32786/
* timeout on name lookup is not supported
*   Trying ::1...
* Connected to localhost (::1) port 32786 (#0)
> GET / HTTP/1.1
> Host: localhost:32786
> User-Agent: curl/7.50.1
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
FROM golang:1.6-onbuild
EXPOSE 80
CMD ["app"]
package main
import (
"fmt"
"net/http"
)
func main() {
fmt.Println("Beginning")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Got a request")
fmt.Fprint(w, "Thank you for your request")
})
fmt.Println("Handler registered")
err := http.ListenAndServe("localhost:80", nil)
if err != nil {
fmt.Println("Running ListenAndServe failed")
panic(err)
}
fmt.Println("End")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment