Running your Go Docker container on an EC2 instance
Once we have a Docker image and Docker installed on an EC2 instance, then you can simply run the Docker container by executing the docker run
command, which we will cover in this recipe.
How to do it…
Login into an EC2 instance and execute the docker run
command to create and run a Docker container from arpitaggarwal/golang-image
, assigning the container name as golang-container
, using the --name
flag, as follows:
$ docker run -d -p 80:8080 --name golang-container -it arpitaggarwal/golang-image 8a9256fcbffc505ad9406f5a8b42ae33ab3951fffb791502cfe3ada42aff781e
The -d
flag specified in the docker run
command starts the container in a daemon mode and the hash string at the end represents the ID of the golang-container
.
The -p
flag specified in the docker run
command publishes a container's port(s) to the host. As we have an HTTP server running on port 8080
inside a Docker container and we opened port 80
for inbound traffic of our E2C instance...