Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all...

24
Debugging in Docker Pat Pannuto / Amrit Hariharan 1 / 24

Transcript of Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all...

Page 1: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Debugging in Docker

Pat Pannuto / Amrit Hariharan 1 / 24

Page 2: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Current Debugging Work�ow1. Write code2. Compile3. Run in GDB/Valgrind

2 / 24

Page 3: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Current Debugging Work�ow1. Write code2. Compile3. Run in GDB/Valgrind

Issues?Different version of g++/valgrind from CAENCan't use Valgrind/GDB if you're on mac/windows

3 / 24

Page 4: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Alternatives?Go to a CAEN computerSSH into CAENVirtual MachineDocker!

4 / 24

Page 5: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

What is Docker?A form of virtualisationContainerise everything!

5 / 24

Page 6: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

But That's Just a VM?It doesn't create the entire OSAll images used shared resources

6 / 24

Page 7: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Docker

Is much quicker to startHella fastOpen source :DAlmost 0 overhead

VM's

Full isolationYou know how it works

But That's Just a VM?It doesn't create the entire OSAll images used shared resources

Which is Better?

7 / 24

Page 8: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Getting StartedDownload Docker (if you haven't already)Start the Docker clientdocker pull alpine

docker run alpine

8 / 24

Page 9: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Getting StartedDownload Docker (if you haven't already)Start the Docker clientdocker pull alpine

docker run alpine

Why didn't that do anything?

You didn't give it any commandsdocker run -it alpine to open an interactive shell

9 / 24

Page 10: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

What We NeedA linux image (Ubuntu 17.10)Valgrind, GDB, etc.

10 / 24

Page 11: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

What We NeedA linux image (Ubuntu 17.10)Valgrind, GDB, etc.

Setting up an Imagedocker pull ubuntu:artful

docker run -it alpine

apt-get update

apt-get install g++ valgrind make

11 / 24

Page 12: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Building the Docker WayUse a Dockerfile

This contains all the commands a user would call on the commandline to assemble an imageMakes it easy to share images, since you only need to share a simpletext file

# Build a simple ubuntu image with vim installed

FROM ubuntu:artful

RUN apt-get update

RUN apt-get install -y vim

CMD ["bash"]

$ docker build .

12 / 24

Page 13: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Accessing Your FilesWe hate two options:

Copy over filesADD . /DOCKER/PATH

Mount directorydocker run -it -v "$(pwd):/DOCKER/PATH

13 / 24

Page 14: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Time to Build a Debugging Container

14 / 24

Page 15: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

The Docker�leObjective

Build an image running ubuntu that has all the tools we need

15 / 24

Page 16: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

The Docker�leGet the linux distro we want

# Using Ubuntu 17:01 (artful)

FROM ubuntu:artful

16 / 24

Page 17: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

The Docker�leInstall everything we need

RUN apt-get update

RUN apt-get install -y g++

RUN apt-get install -y gcc

RUN apt-get install -y make

RUN apt-get install -y valgrind

RUN apt-get install -y vim

17 / 24

Page 18: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

The Docker�leGet it ready to be run

# Set starting directory to /prog

RUN mkdir /prog

WORKDIR /prog

# Run bash

CMD ["bash"]

18 / 24

Page 19: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

The Docker�le# Using Ubuntu 17.10

FROM ubuntu:artful

RUN apt-get update

RUN apt-get install -y g++

RUN apt-get install -y gcc

RUN apt-get install -y make

RUN apt-get install -y valgrind

RUN apt-get install -y vim

# Set starting directory to home

RUN mkdir /prog

WORKDIR /prog

CMD ["bash"]

19 / 24

Page 20: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Build ItIf you're in the same directory as the Dockerfile

docker build -t docker-debugger .

If not

docker build -f /PATH/TO/Dockerfile -t docker-debugger

20 / 24

Page 21: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Running ItRun the most recent 'docker-debugger' image

# Run it

# Mount the current directory to /prog

docker run -it --rm --privileged \

-v "$(pwd):/prog" docker-debugger:latest

21 / 24

Page 22: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Running ItWhat are all those other �ags??

-it : open an interactive shell--rm : remove the container on exit--privileged : give it permissions required for gdb/valgrind-v "LOCAL_PATH:CONTAINER_PATH" : Mount LOCAL_PATH on your container atCONTAINER_PATH

22 / 24

Page 23: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Is That It?This is a really simple use caseDeploy a website anywhere

Have loads of images + a load balancer!

23 / 24

Page 24: Debug ging in Docker · 2020. 4. 10. · Building the Docker Way Use a Dockerfile This contains all the commands a user would call on the command line to assemble an image Makes it

Is That It?Container Orchestration

Managing loads and loads of running containersScaling as appropriate by adding or removing containersDistributing load between the containersLaunching new containers on different machines if something fails

24 / 24