Run a Docker image as a container
After building a Docker image from a dockerfile
, I see the image was built successfully, but what do I do with it? Shouldn't i be able to run it as a container?
The specific way to run it depends on whether you gave the image a tag/name or not.
$ docker images
REPOSITORY TAG ID CREATED SIZE
ubuntu 12.04 8dbd9e392a96 4 months ago 131.5 MB (virtual 131.5 MB)
With a name (let's use Ubuntu):
$ docker run -i -t ubuntu:12.04 /bin/bash
Without a name, just using the ID:
$ docker run -i -t 8dbd9e392a96 /bin/bash
Please see Docker run reference for more information.
Do the following steps:
-
$ docker images
You will get a list of all local Docker images with the tags specified.
-
$ docker run image_name:tag_name
If you didn't specify
tag_name
it will automatically run an image with the 'latest' tag.Instead of
image_name
, you can also specify an image ID (no tag_name).
-
To list the Docker images
$ docker images
-
If your application wants to run in with port 80, and you can expose a different port to bind locally, say 8080:
$ docker run -d --restart=always -p 8080:80 image_name:version