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
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
Where:
--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.
You can see your available images using:
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 run -d repository
docker run -d repository:tag
docker run -d image_id
Then you can check your container is running using
docker ps
docker ps
gives you a container ID. You can use it or just the 2/3 first characters to go into 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 automatically be removed.
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.
You can run this container in the following way:
$ docker run -d -e USERNAME=test -e PASSWORD=test -p 8888:80 morrisjobke/webdav
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).
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:
First run your Docker image:
docker run -it -p 8888:8888 -p 6006:6006 -v ~/:/host waleedka/modern-deep-learning
Then list all the containers you have made:
sudo docker ps -a
And select the container you want to work with (mine is 167ffffd6d7f15):
sudo docker start -ai 167ffffd6d7f15