-
Notifications
You must be signed in to change notification settings - Fork 13
Docker guide
- Prerequisites
- Brief Description
- Anatomy of a Normal Flow of build explained
- See your existing images
- See your existing containers
- Copy files inside the container
- VS Code work with docker
- Docker / Docker desktop
- Git
- VSCode
- Docker extension
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.
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
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.
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
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
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
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
If as me you expect to work with VSCode, here is the workflow for it.
- 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
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.
Open de Command Pallete
If the name of the machine is jovial_poincare for example, select it
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