Skip to content

Docker guide

Ðavid edited this page Feb 21, 2024 · 8 revisions

Index

Prerequisites

  • Docker / Docker desktop
  • Git

Would be great

Brief Description

Working with Docker for a normal user it's like working with a Virtual Machine, but in the CLI, without user interface. There are plugins like the one from VSCode that can help us working with Docker.

When working with Docker, you have basically 2 parts:

  • Operating System, that is builded using the Dockerfile and creates an Image.
  • Instances of that OS, what will be called container, each has a different name.

Docker it's in theory OS agnostic, so everything applies to Windows, Linux or Mac OS.

Anatomy of a Normal Flow of build explained

First we do non docker stuff, so we clone the repository to have access to everything.

git clone https://github.com/Deivitto/auditor-docker.git

We dive into the folder

cd auditor-docker

Create an image / OS

Now, we do the docker build. Parts:

  • docker build: Is the command to create an Image
  • -t assigns a tag, :latest is assigned if no tag is provided.
  • . means Dockerfile is in the current folder.

Examples:

docker build -t name-of-the-image .
docker build -t name-of-the-image:latest . #is the same as the previous command
docker build -t name-of-the-image:v2 . #so we can use the same name of the image with different tags. This brings clarity and order, that's it.

So in conclusion, docker build is used to create the OS we are gonna use.

Create an instance / container

Now we create a working instance of the OS, for that we use docker run. Parts:

  • docker run: Is the command to create instances or Containers
  • -d: means detached, so basically runs the process without showing you anything on the CLI, this is good for attaching to VSCode without extra windows.
  • --rm: 1 use instance. After exit everything is erased. Good for testing.
  • -it: to start a container and immediately begin interacting with its terminal
  • -v "$PWD":/home/whitehat/any-shared-folder-name: This specifies a volume in this case current folder (PWD) to be mounted as any-shared-folder-name in the container
  • --ulimit stack=100000000:100000000: To increase maximum stack size (i.e. to use manticore)

Examples:

docker run -it name-of-the-image # basic command
docker run -it -v "$PWD":/home/whitehat/any-shared-folder-name name-of-the-image  # sharing current folder as any-shared-folder-name
docker run -it -d --rm name-of-the-image # some useful options
docker run -it --ulimit stack=100000000:100000000 -d --name container-name name-of-the-image  # i.e. to use manticore

See your existing images

Recover all existing images in a table:

REPOSITORY            TAG       IMAGE ID       CREATED             SIZE
v0.1.1                latest    6da33972ddad   4 days ago          4.17GB
docker images

See your existing containers

CONTAINER ID   IMAGE             COMMAND       CREATED       STATUS                     PORTS     NAMES
aba112043b4c   v0.1.1            "/bin/bash"   2 weeks ago   Up 11 days                           jovial_poincare
docker ps -a

Copy files inside the container

In case you don't want to share a whole folder and you just want to copy files inside sometimes, here is a command:

docker cp file.txt containerID:home/whitehat/whatever-folder

VS Code work with docker

If as me you expect to work with VSCode, here is the workflow for it.

Pre-requisite

  • You need a builded image
  • Run an image as mentioned before.
  • NOTE: If you have a already existing container, run docker start NAME_OF_THE_CONTAINER/ID_OF_THE_CONTAINER
  • VSCode Docker extension

Now

After installing the extension, run the command palette and type Attach to running container.... This command will attach the instance of the machine to the VSCode instance.

VS Code

Open de Command Pallete

Command Pallette

If the name of the machine is jovial_poincare for example, select it

Attach To

NOTE: You can docker run -d to run the docker machine in the background, with the objective of using the VSCode docker extension.

Note: Work in Progress