Docker
DOCKER¶
**Docker is a software container platform that allows you to create, distribute and run applications in isolated environments. This means that you can package applications with all their dependencies and configurations in a container that can be easily moved from one machine to another, regardless of operating system or hardware configuration.
Some of the advantages when it comes to hacking using Docker are:
- Isolation: Docker containers are isolated from each other, meaning that if an application within a container is compromised, the rest of the system will not be affected.
- Portability**: Docker containers can be easily moved from one system to another, making them ideal for deploying vulnerable environments for hacking practices.
- Reproducibility: Docker containers can be configured accurately and reproducibly, which is important in hacking to be able to recreate attack scenarios.
docker file¶
A Dockerfile file is composed of several sections, each of which begins with a keyword in shift, followed by one or more arguments.
Some of the most common sections in a Dockerfile are:
- FROM: used to specify the base image from which the new image will be built.
- RUN**: used to execute commands inside the container, such as installing packages or configuring the environment.
- COPY**: used to copy files from the host system to inside the archive.
- CMD**: used to specify the command to be executed when the archive is started.
In addition to these sections, other instructions for configuring the environment, installing additional packages, exposing network ports and more can also be included.
Port Forwarding and mounts¶
Port forwarding, also known as port forwarding, allows us to redirect network traffic from a specific port on the host to a specific port in the container. This will allow us to access services running inside the container from the outside.
To use port forwarding, the "-p" or "-publish" option is used in the "docker run" command. This option is used to specify port forwarding and can be used in several ways. For example, if you want to redirect port 80 of the host to port 8080 of the container, you can use the following syntax:
➜ docker run -p 80:8080 my_image
.
This will redirect any incoming traffic on port 80 of the host to port 8080 of the container. If you wish to specify a protocol other than the default TCP protocol, you can use the "-p" option with a different format. For example, if you want to redirect port 53 of the host to port 53 of the container using the UDP protocol, you can use the following syntax:
➜ docker run -p 53:53/udp my_image
.
Mounts**, on the other hand, allow us to share a directory or file between the host system and the container. This will allow us to persist information between container runs and share data between different containers.
To use the mounts, the "-v" or "-volume" option is used in the "docker run" command. This option is used to specify the mount and can be used in several ways. For example, if you want to mount the "/home/user/data" directory of the host to the "/data" directory of the container, you can use the following syntax:
➜ docker run -v /home/user/data:/data my_image
.
This will mount the "/home/user/data" directory of the host into the "/data" directory of the container. If you wish to specify an additional option, such as mounting the directory in read-only mode, you can use the "-v" option with a different format. For example, if you want to mount the directory in read-only mode, you can use the following syntax:
➜ docker run -v /home/user/data:/data:ro my_image
.
docker compose¶
Docker Compose is a container orchestration tool that allows you to define and run multi-container applications easily and efficiently. With Docker Compose, we can describe the different services that make up our application in a YAML file and then use a single command to run and manage all these services in a coordinated manner.
In other words, Docker Compose allows us to define and configure multiple containers in a single YAML file, which simplifies the management and coordination of multiple containers in a single application. This is especially useful for complex applications that require the interaction of several different services, as Docker Compose allows you to easily define and configure the connection and communication between these services.
-
downloads docker
-
install dependencies with docker database
-
start the demon of docker
-
dockerfile → an archive with coding of the dockerfile
-
for every change in images make
-
upload image
-
show the images and volume of dockers
-
verify if the container is running
-
connection with container
-
install all dependencies
-
modify image
-
update with version 2
-
create an new container with v2 image
-
stop a container
-
delete container
-
delete images
-
show all container ID
port forwarding and mount¶
-
create dockerfile
FROM ubuntu:latest MAINTAINER R3D4L1T ENV DEBIAN_FRONTEND noninteractive # quit the interactive mode RUN apt update && apt install -y net-tools \ iputils-ping \ curl \ git \ nano \ apache2 \ php EXPOSE 80 # expose the port 80 for usage in webpage ENTRYPOINT service apache2 start && /bin/bash # execute when start container
-
create a image with docker image previus
-
create a docker container
-
verify configurations
-
show logs
mounts¶
for syncronize files in the psycal machine with Docker container this is in the creation of the container
docker run -dit -p 80:80 -v /PATH_whenIs_myFile/: /PATH_inDockerContainer/ --name mywebserver webserver # the PATH only Directory without name of file
- other shape of to do this is:
FROM ubuntu:latest MAINTAINER R3D4L1T ENV DEBIAN_FRONTEND noninteractive # quit the interactive mode RUN apt update && apt install -y net-tools \ iputils-ping \ curl \ git \ nano \ apache2 \ php COPY file.txt /PATHofthecontainer EXPOSE 80 # expose the port 80 for usage in webpage ENTRYPOINT service apache2 start && /bin/bash # execute when start container
docker-Compose¶
-
clone a project of github but if is an subcarpet of poject in github run the next code
-
for run the file You are in the same directory
-
for show the logs