You are on page 1of 20

Working with

Containers
Command Reference:
https://gist.github.com/initcron/08108141438895252de8
Objectives

• Learn how to work with containers


• Launching a Web App with existing
image
• Network Port Mapping
• Container Operations e.g. inspecting,
checking stats, file copying, removing etc.
In the last session we created a few
containers running hello world app. We are
now going to look at more practical example.
We will launch a container from an existing
image and start a web application.
Launching Web App
$ docker run -d -P training/webapp
python app.py
port mapping

web app
Checking Status

$ docker ps
Port Mapping

host 32768 5000

container

Adding -P option maps port 5000 to port


49153 on our host
-P == -p 5000
Discovering Port Mapping

$ docker port <container_id>


This port is mapped to the VM
and not to host directly. To find
out the ip of the VM run the
following command (on
win/mac host)

$ docker-machine ip default
Validate

http://docker_machine_ip:port
Checking Logs
$ docker logs <container_id>
Show Process Table
$ docker top <container_id>
Show Run Stats
$ docker stats --no-stream=true
<container_id>
Inspecting Container
$ docker inspect <container_id>
Copy Files to and From
Container

$ touch localfile
$ docker cp localfile <container_id>:/opt/
$ docker cp <container_id>:/opt/webapp .
$ docker diff <container_id>
Rename a Container

$ docker rename <container_id> webapp


$ docker ps
Stopping Container
$ docker stop webapp
$ docker ps -l
Removing Container
$ docker rm webapp
$ docker ps -l
Exercise
• Create/Run a new container and limit its
memory to 300M while launching it.

• Hint: look at docker run --help for options


to control resource utilization e.g.
memory, cpu
Summary
• Launching Containers from pre built
image
• Connecting to Applications, Port Mapping
• Container Operations

You might also like