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.