You are on page 1of 20

Session 2

• Manipulating container with Docker client


• Docker Run

Creating and Running a


container from an image

Create and run a


container

docker run <image name>

Reference the Name of the image to use for


Docker Client this container
Container

Image
File system Startup
Running
Process snapshot command

Hello-world # run hello-world

System call to
access HDD

Kernel

RAM CPU Network


Hard Disk
Hard disk
segment for
this process
Docker Run

Creating and Running a


container from an image

Create and run a


container Default command override

docker run <image name> command

Reference the Name of the image to use for


Docker Client this container
Container

Busy box Image


Running File system Startup
Process snapshot command
bin dev etc
ls
???
home proc root

System call to
access HDD

Kernel

RAM CPU Network


Hard Disk
Hard disk
segment for
this process
• Docker ps
• Container lifecycle

Creating and Running a


container from an image

Create and run a


container

docker run <image name>

Reference the Name of the image to use for


Docker Client this container
• Container lifecycle

Creating and Running a


container from an image

docker run = docker create + docker start


• Container lifecycle
Create a container

Creating a container
from an image
docker create <image name>

Reference the Name of the image to use for


Docker Client this container

Start a container

Running a container
from an image
docker start <container id>

Reference the ID of the container to start


Docker Client
• Container lifecycle
Container

Image
Create Container
File system Startup
Start Container Running
Process snapshot command

Hello-world # run hello-world

System call to
access HDD

Kernel

RAM CPU Network


Hard Disk
Hard disk
segment for
this process
• Container lifecycle
Container

Image
Create Container
File system Startup
Start Container Running
Process snapshot command

busybox $ echo hi

System call to
access HDD

Kernel

RAM CPU Network


Hard Disk
Hard disk
segment for
this process
• Removing stopped containers
$ docker system prune
• Container logs

Get logs from a container

Get logs

docker logs <container ID>

Reference the ID of the container to look at


Docker Client
• Stopping containers

Stop a container
docker stop <container id>

Reference the ID of the container to start


Docker Client

Kill a container
docker kill <container id>

Reference the ID of the container to start


Docker Client
Container

stop SIGTERM Ping google.com


Running
Process

System call to
access HDD

Kernel

RAM CPU Network


Hard Disk
bin dev etc Hard disk
segment for
home proc root
this process
Container

kill SIGKILL ping google.com


Running
Process

System call to
access HDD

Kernel

RAM CPU Network


Hard Disk
bin dev etc Hard disk
segment for
home proc root
this process
• Multicommand containers

redis-server

redis-cli
Container

redis-server
Running
Process
redis-cli

System call to
access HDD

Kernel

RAM CPU Network


Hard Disk
bin dev etc Hard disk
segment for
home proc root
this process
• Execute additional command in a container

Run another
command ID of the container to look at

docker exec -it <container ID> <command>

Reference the Allows us to Command to execute


Docker Client provide input to
the container
• -it flag

ping google.com redis-cli ls

STDIN STDOUT STDERR STDIN STDOUT STDERR STDIN STDOUT STDERR

Stuff shows up on
Stuff you type
the screen
terminal

You might also like