Run a Docker Image as a Container

2019-01-20 21:34发布

I built a docker image from a dockerfile. I see the image was built successfully, but what do I do with it? Shouldn't it be able to run as a container?

New to docker so probably a misunderstanding on my end, any help would be great.

7条回答
可以哭但决不认输i
2楼-- · 2019-01-20 21:34

I had the same problem. I ran my docker and it created a container with a specific CONTAINER_ID and I wanted to work with the same container:

first run your docker:

$docker run -it -p 8888:8888 -p 6006:6006 -v ~/:/host waleedka/modern-deep-learning

Then list all container you have made:

$sudo docker ps -a

and select the container you want to work with (mine is 167ffffd6d7f15)

$sudo docker start -ai 167ffffd6d7f15

查看更多
对你真心纯属浪费
3楼-- · 2019-01-20 21:36

The specific way to run it depends on whether you gave the image a tag/name or not.

$ docker images
root@dockertest:~# 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 https://docs.docker.com/engine/reference/run/ for more information.

查看更多
可以哭但决不认输i
4楼-- · 2019-01-20 21:36

Get the name or id of the image you would like to run, with this command: docker images

The docker run command is used in the following way:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Below I have included the dispatch, name, publish, volume and restart options before specifying the image name or id:

docker run -d --name  container-name -p localhost:80:80 -v $HOME/myContainer/configDir:/myImage/configDir --restart=always image-name

--detach , -d Run container in background and print container ID --name Assign a name to the container --publish , -p Publish a container’s port(s) to the host --volume , -v Bind mount a volume --restart Restart policy to apply when a container exits

For more information please check out the official docker run reference

查看更多
Deceive 欺骗
5楼-- · 2019-01-20 21:39

Here is an example to run a webdev service in docker.
The image's name is morrisjobke/webdav. You can pull it from dockerhub.

After you run this images,you can then access the WebDAV instance at http://localhost:8888/webdav. Internally the folder /var/webdav is used as WebDAV root.

You can run this container in following way: $ docker run -d -e USERNAME=test -e PASSWORD=test -p 8888:80 morrisjobke/webdav

查看更多
三岁会撩人
6楼-- · 2019-01-20 21:43
  • 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
查看更多
走好不送
7楼-- · 2019-01-20 21:46

You can see your availables images using

docker images

Then you can run in detached mode

docker run -d myimage

Then you can check your container is running using

docker ps

docker ps give you a docker id, you can use it or just the 2/3 firsts character to gointo your container using

docker exec -it container_id /bin/bash

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 be automatically removed.

查看更多
登录 后发表回答