Run a Container
The docker run command starts a new container from an image. Let’s break down the syntax:
# This is just an example, don't run this
docker run -d -p hostport:containerport namespace/name:tag
-d: Run in detached mode (doesn’t block your terminal)-p: Publish a container’s port to the host (forwarding)hostport: The port on your local machinecontainerport: The port inside the containernamespace/name: The name of the image (usually in the format username/repo)tag: The version of the image (oftenlatest)
Example: Getting Started Container
Use the run command to start a new container from the “getting started” image:
docker run -d -p 8965:80 docker/getting-started:latest
You can view running containers using:
docker ps
In the output, you should see something like this under the PORTS column:
0.0.0.0:8965->80/tcp
This means that port 8965 on your local “host” machine is being forwarded to port 80 on the running container. Port 80 is conventionally used for HTTP web traffic. You can navigate to http://localhost:8965 in your browser, and you should see a webpage served directly from the container!