A Docker image is a template for an application, together with its dependencies, runtime environment and metadata.
A Docker container is a running instance of a Docker image.
docker run --help
Follow run
by an image name to download that image (if it's not already present) and run a container from it:
Containers may be terminating, and so have a finite lifespan:
docker run hello-world
or containers may try to run forever:
docker run training/webapp
Use Ctrl+C to end a terminal session linked to a container.
docker ps
docker stop 8c2c34626f7b
docker run -d training/webapp
-p
lets you specify your own port mappings, with an argument. The below maps host port 9000 to container port 5000:
docker run -d -p 9000:5000 training/webapp
Multiple -p
arguments can be passed, each with their own argument:
docker run -d -p 5000:5000 -p 6000:6000 training/webapp
-P
uses image metadata to provide suitable mappings:
docker run -d -P training/webapp
docker run -it training/webapp /bin/bash
Leave with exit
docker run -Pd -e PROVIDER=User training/webapp
The -e
argument can be specified multiple times, each for a different environment variable.
docker run -v C:\Users\goldsteing\dockertest:/usr/share/nginx/html -Pd nginx