stackoverflow.comquestions18497688run-a-docker-image-as-a-container
stackoverflow.comquestions18497688run-a-docker-image-as-a-container
727
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?
docker docker‐image
ShareFollow edited Aug 26, 2020 at 8:50 asked Aug 28, 2013 at 20:34
Alonme boom
1,313 14 28 10.7k 9 43 64
12 Answers Sorted by: Highest score ﴾default﴿
1017
The specific way to run it depends on whether you gave the image a tag/name or not.
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose
information
$ docker imagesin accordance with our Cookie Policy.
REPOSITORY TAG ID CREATED SIZE
ubuntu 12.04 8dbd9e392a96 4 months ago 131.5 MB (virtual
131.5 Accept
MB) all cookies Necessary cookies only
Customize settings
With a name ﴾let's use Ubuntu﴿:
ShareFollow edited Nov 17, 2019 at 22:37 answered Aug 28, 2013 at 21:14
Peter Mortensen Andy
31k 21 104 131 35.3k 5 43 50
7 So the human‐friendly names printed under 'NAME' in docker ps ‐a is not useful here? – ThorSummoner
Aug 23, 2015 at 4:19
15 docker ps lists containers, not images. If you want to create an image from a container, you must docker
commit . You can use the NAME in the commit ﴾e.g. docker commit _NAME_ _imagename_ ﴿ – Andy Aug 24,
2015 at 18:56
12 @Andy Why do we use /bin/bash at the end ? I am new also – Raheel Jul 7, 2016 at 16:54
8 @RaheelKhan Becaue your docker image needs something to run. You could replace that with a program that
you've installed. /bin/bash is just a handy shell that's already installed. – Ryan Shillington Feb 9, 2017 at 15:11
1 If you need to add an environment variable you can do docker run ‐i ‐t ‐e ROOT_PASSWORD=root
ubuntu:12.04 – Balaji Radhakrishnan Dec 16, 2017 at 14:23
93
1. $ docker images
You will get a list of all local Docker images with the tags specified.
ShareFollow edited Nov 17, 2019 at 22:38 answered May 17, 2016 at 7:04
Peter Mortensen kalyani chaudhari
31k 21 104 131 7,475 3 24 21
I'm new to docker, it helps me, Thanks. Further we can check statuses for running images sudo docker ps ‐a
– WK5 Mar 1, 2021 at 11:46
48
$ docker images
If your application wants to run in with port 80, and you can expose a different port to bind
locally, say 8080:
ShareFollow edited Nov 17, 2019 at 22:47 answered Aug 8, 2017 at 5:47
Peter Mortensen Murali Manchadikkal
31k 21 104 131 887 1 10 7
2 This ‐‐restart=always option should be used always as a rule. – Arefe Nov 9, 2021 at 8:36
32
docker images
Then you can run in detached mode so your terminal is still usable. You have several options to run it
using a repository name ﴾with or without a tag﴿ or image ID:
docker ps
gives you a container ID. You can use it or just the 2/3 first characters to go into your
docker ps
container using:
And you can stop it using docker stop container_id and docker rm container_id .
You can also run your container with ‐‐rm arguments so if you stop your container it will automatically
be removed.
2 The ‐‐rm ﴾note: 2 dashes not single﴿ option is gold!!!, my system is littered with stopped ﴾dead﴿ containers.
– Johan Snowgoose Jul 14, 2019 at 21:40
15
Get the name or id of the image you would like to run, with this command:
docker images
Below I have included the dispatch, name, publish, volume and restart options before specifying the
image name or id:
Where:
For more information, please check out the official Docker run reference.
ShareFollow edited Nov 17, 2019 at 22:51 answered Jun 13, 2018 at 0:12
Peter Mortensen JSON C11
31k 21 104 131 11.1k 7 78 65
11
I had the same problem. I ran my Docker image, and it created a container with a specific
CONTAINER_ID. I wanted to work with the same container:
sudo docker ps ‐a
And select the container you want to work with ﴾mine is 167ddd6d7f15﴿:
ShareFollow edited Nov 17, 2019 at 22:52 answered Oct 29, 2018 at 9:08
Peter Mortensen farnaz jazayeri
31k 21 104 131 625 6 7
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
apache_snapshot latest 13037686eac3 22 seconds ago 249MB
ubuntu latest 00fd29ccc6f1 3 weeks ago 111MB
Now you can run the Docker image as a container in interactive mode:
OR if you don't have any images locally,Search Docker Hub for an image to download:
Pull the Docker image from a repository with the docker pull command:
Here is an example to run a webdev service in Docker. The image's name is morrisjobke/webdav. You
can pull it from Docker Hub.
After you run these images, you can then access the WebDAV instance at
http://localhost:8888/webdav . Internally the folder /var/webdav is used as the WebDAV root.
ShareFollow edited Nov 17, 2019 at 22:43 answered Mar 3, 2017 at 5:58
Peter Mortensen Yang Yu
31k 21 104 131 302 3 8
Re "run a webdev service": Do you mean "run a WebDAV service"? Or "run a web development service"?
– Peter Mortensen Nov 17, 2019 at 22:46
6
Since you have created an image from the Dockerfile, the image currently is not in active state. In
order to work you need to run this image inside a container.
The $ docker images command describes how many images are currently available in the local
repository. and
docker ps ‐a
shows how many containers are currently available, i.e. the list of active and exited containers.
In detached mode:
‐d=false: Detached mode: Run container in the background, print new container id
In interactive mode:
For more clarification on Docker run, you can visit Docker run reference.
ShareFollow edited Nov 17, 2019 at 22:54 answered Feb 22, 2019 at 8:36
Peter Mortensen Rajat Tyagi
31k 21 104 131 141 3 10
1
Hey,
docker ps ‐all 4. Finally open your google chrome and type localhost:3030
$ docker images
REPOSITORY TAG IMAGE ID CREATED
jamesmedice/marketplace latest e78c49b5f380 2 days ago
jamesmedice/marketplace v1.0.0 *e78c49b5f380* 2 days ago
ShareFollow
ShareFollow answered Sep 16, 2019 at 11:40
Tiago Medici
1,904 22 22
For those who had the same problem as well, but encountered an error like
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting
container process caused "exec: \"bash\": executable file not found in $PATH"
docker run ‐it ‐‐entrypoint /bin/sh for the images without Bash.
Reference: https://gist.github.com/mitchwongho/11266726
ShareFollow edited Nov 17, 2019 at 22:57 answered Sep 3, 2019 at 3:22
Peter Mortensen Raihanhbh
31k 21 104 131 67 10
Highly active question. Earn 10 reputation ﴾not counting the association bonus﴿ in order to answer this
question. The reputation requirement helps protect this question from spam and non‐answer activity.