This is a simple example on how to run a Go-based http server using Docker.
You should already have Docker installed in your build machine. After cloning this repo, run the following commands:
$ cd <clone-directory>
$ docker build --rm .The above command will use the tag latest. If you want to have a different tag, say v0:
$ docker build --rm -t hellohttpserver:v0 .In DockerHub, ulimitns is our organization namespace. Let's use v0 tag for this example.
$ docker login # using your DockerHub account
$ docker tag hellohttpserver:v0 ulimitns/hellohttpserver:v0
$ docker push ulimitns/hellohttpserver:v0You can use these commands to run the image, say in a new server.
# Download the image:
$ docker pull ulimitns/hellohttpserver:v0
# Run the image:
$ docker run -d -p 8080:8080 ulimitns/hellohttpserver:v0
# Or if you want your server to autorestart when host restarts:
$ docker run -d -p 8080:8080 --restart=always ulimitns/hellohttpserver:v0
# Test the server:
$ curl -v localhost:8080/hello$ docker ps -a
CONTAINER ID IMAGE COMMAND STATUS ... NAMES
8e8e4cc68279 ulimitns/hellohttpserver:v0 ... ... ... agitated_hellman
# Delete the running server:
$ docker rm -f agitated_hellman