In [ ]:
docker run --rm hello-world
Congratulations! You are using Docker like a boss. Let's break down what just happened:
run
command told Docker to do two things: create a new container and start it.--rm
parameter is optional, and told Docker to remove the container once it is finished executing.hello-world
parameter told Docker to base the container on an image named "hello-world".
In [ ]:
docker run --detach --name whoa --publish 80:8080 rackerlabs/whoa
That was similar to running hello-world, but with a few new parameters.
--name whoa
... steal from diff--detach
told Docker to run the container in the background and print the container Id.publish 80:8080
told Docker to publicly expose port 8080 from the container as port 80. By default a container is walled-off from the world, and this enables us to view the website hosted by our container.Now, let's get some more information on your container:
In [ ]:
docker ps --filter="name=whoa"
The docker ps
command is similar to the ps command on Mac or Linux. It prints information about every container on your Docker host.
--all
told Docker to include stopped/exited containers.--filter="name=whoa"
limited the results to just our whoa container.Let's look at the info we have to work with:
Notice that the whoa container is still running, this let us leave off the --all
parameter. Also since we used the --publish
parameter, the public IP address and port of the container is listed.
Now you could copy/paste that IP address from the docker ps
output into your web browser, but here's a shortcut to build a link to the website hosted on the container. Run the command below and click on the link to take a peek at your website:
In [ ]:
echo http://$(docker port whoa 8080)
Now that we are finished with our whoa
container, let's remove it and free up port 80.
In [ ]:
docker rm --force whoa
The docker rm
command deletes a container either by its name or id. Since our container was still running, we specified --force
to tell Docker to first stop the container. When the command completes, it prints the names of any deleted containers.