Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Default ports are 2375, 2376.
Investigation
Find Docker Binary
If we cannot use docker command by default, we need to find the docker binary.
find/-name"docker"2>/dev/null
Basic Commands
# List imagesdockerimagesdockerimagels# The history of an imagedockerimagehistory<image-name># List containers runningdockercontainerls# ordockerps# List all containersdockercontainerls-a# ordockerps-a# List secretsdockersecretls# Check configuration of containerdockerinspect--format='{{json .Config}}'<container_id_or_name># Get a port which is used by the containerdockerport<container_id_or_name># Scan vulnerabilies (CVEs)dockerscancves<image>dockerscancvesalpine# View the SBOM (Software Bill of Materials) for an image# We can investigate vulnerabilities from the list of packages.dockersbomalpine:latest# Json formatdockersbomalpine:latest--formatsyft-json# Spawn the shell in the containerdockerexec-it<container_id>/bin/bash# Kill the running docker containerdockerkill<container_id>
Check if Containers Running
In target machine, observe the network status by running netstat or ss command.
# -d: detached mode (background)# -p: map the port of the host to the port in the containerdockerrun-dp80:80<image-name>
If you want to run a new container from a remote repository, run the following.
# --rm: Removes the anonymous volumes when the container is removed# -i: interactive# -t: tty# --network=host: The container is not isolated from the Docker host. The IP address is your own home IP address.dockerrun--rm-it--network=host<repository>/<image># /bin/bash: spawn a shell within the containerdockerrun-itnginx/bin/bash
Start a Container which is stopped
# List all containers and check the target IDdockercontainerls-a# Start the containerdockercontainerstart<container-id>
Run Commands in a Container
# List containers running and check the target container IDdockerps# Run commands by giving the container IDdockerexec<container-id>whoamidockerexec<container-id>catsample.txt
Stop a Container
# List running containers and check the target container IDdockerps# Stop the container by giving the IDdockerstop<container-id>
Remove a Container
# List all containers and check the target container IDdockerps-a# Remove the container by givine the IDdockerrm<container-id># Force to remove the running container (-f)dockerrm-f<container-id>
Build a Container Image
First off, create a Dockerfile in the root directory of the project.
Now run the following command to build the container image.
This command uses the Dockerfile.
# -t: name a tag of the imagedockerbuild-t<tag-name>.
Scan a Container Image
dockerscan<image-name>
Pull a Docker Image
We need to download a docker image to start a container at first.
dockerpull<image>dockerpullnginx# Specify a tagdockerpull<image>:<tag>dockerpullnginx:latestdockerpullnginx:stable
Remove a Docker Image
# List images and check the target image IDdockerimages# Remove the image by giving the IDdockerrmi<image-id>
Publish a Docker Image
Before doing below, you need to sign up the Docker Hub and sign in, then create a new repository in your dashboard.
# Logindockerlogin-u<your-username># Tag a new imagedockertag<source-image><your-username>/<target-image># Pushdockerpush<your-username>/<target-image>