---
title: Run your Go image as a container
linkTitle: Run containers
weight: 10
keywords: get started, go, golang, run, container
description: Learn how to run the image as a container.
aliases:
- /get-started/golang/run-containers/
- /language/golang/run-containers/
- /guides/language/golang/run-containers/
---
## Prerequisites
Work through the steps to containerize a Go application in [Build your Go image](build-images.md).
## Overview
In the previous module you created a `Dockerfile` for your example application and then you created your Docker image using the command `docker build`. Now that you have the image, you can run that image and see if your application is running correctly.
A container is a normal operating system process except that this process is isolated and has its own file system, its own networking, and its own isolated process tree separate from the host.
To run an image inside of a container, you use the `docker run` command. It requires one parameter and that's the image name. Start your image and make sure it's running correctly. Run the following command in your terminal.
```console
$ docker run docker-gs-ping
```
```text
____ __
/ __/___/ / ___
/ _// __/ _ \/ _ \
/___/\__/_//_/\___/ v4.10.2
High performance, minimalist Go web framework
https://echo.labstack.com
____________________________________O/_______
O\
⇨ http server started on [::]:8080
```
When you run this command, you’ll notice that you weren't returned to the command prompt. This is because your application is a REST server and will run in a loop waiting for incoming requests without returning control back to the OS until you stop the container.
Make a GET request to the server using the curl command.
```console
$ curl http://localhost:8080/
curl: (7) Failed to connect to localhost port 8080: Connection refused
```
Your curl command failed because the connection to your server was refused.
Meaning that you weren't able to connect to localhost on port 8080. This is
expected because your container is running in isolation which includes
networking. Stop the container and restart with port 8080 published on your
local network.
To stop the container, press ctrl-c. This will return you to the terminal prompt.
Start the container and expose port `8080` to port `8080` on the host.
```console
$ docker run --publish 8080:8080 docker-gs-ping
```
Now, rerun the curl command.
```console
$ curl http://localhost:8080/
Hello, Docker! <3
```
Success! You were able to connect to the application running inside of your container on port 8080. Switch back to the terminal where your container is running and you should see the `GET` request logged to the console.
Press `ctrl-c` to stop the container.
## Run in detached mode
This is great so far, but your sample application is a web server and you
shouldn't have to have your terminal connected to the container. Docker can run
your container in detached mode in the background. To do this, you can use the
`--detach` or `-d` for short. Docker will start your container the same as
before but this time will detach from the container and return you to the
terminal prompt.
```console
$ docker run -d -p 8080:8080 docker-gs-ping
d75e61fcad1e0c0eca69a3f767be6ba28a66625ce4dc42201a8a323e8313c14e
```
Docker started your container in the background and printed the container ID on the terminal.
Again, make sure that your container is running. Run the same `curl` command:
```console
$ curl http://localhost:8080/
Hello, Docker! <3
```
## List containers
Since you ran your container in the background, how do you know if your container is running or what other containers are running on your machine? Well, to see a list of containers running on your machine, run `docker ps`. This is similar to how the ps command is used to see a list of processes on a Linux machine.
```console
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES