Docker is an opensource tool used for virtualization and deliver software in the form of packages called Containers. It is one of the most important tools used in networking domain. Dockerfile is a template for building the image which contains commands needed to package the software. In this post, I am going to explain the commands ADD & COPY used in Dockerfile . ADD Command: ADD command is used to copy files, directories or files from remote URLS to destination path in the image. The source paths can contain wildcards. If the destination has relative path, it is relative to the Working directory of the image. Note that source path is always relative to the Docker build context. ADD command will not support authentication. So, if there are any protected files to be added in Dockerfile building, use other tools like curl or wget Dockerfile copying Single & Multiple files, directory using ADD inst...
Docker is an open-source software used to develop and deliver the software in the form of packages known as Containers. This post contains the commands needed for debugging or working with docker. This may require some networking basics and understanding of dockers and containers. All the commands are prefixed with sudo to avoid permission denied problem and run the commands like a root user.
Checking Logs of a single container:
sudo docker container logs <Container_Name_Or_ID> - This command is used to see whether any errors or exceptions occurred due to the programs or applications running in the container.
Display containers in the system:
sudo docker container ls - This command displays the containers running at the current point of time in the system
sudo docker container ls -a - This commands displays all the containers present in the system which also includes containers in the exited state
Display Images in the system:
sudo docker image ls - This command lists the images that are present in the system at the given point of time. Each image will have ID, size, version if mentioned, and the time at which it was created
Display interfaces of container:
sudo docker exec -it < Container_Name_Or_ID > ifconfig - This command displays interfaces present in the container without logging into the container. The output can be redirected to a file if needed for debugging
Display Interface IP associated with docker network of container:
If we are orchestrating docker containers using Docker, there will be docker-compose.yml listing all networks to be associated with the container. Accordingly, the container will have interfaces. To get the particular network associated interface IP address, use the below command
sudo docker inspect --format='{{ .NetworkSettings.Networks.<Network_Name>.IPAddress}}' <Container_Name_or_ID>
Displaying and Inspecting docker networks in the system:
sudo docker network ls - This command lists the docker networks present in the system. One can take any network name and inspect it using sudo docker network inspect <network_name> which returns the output in the format of JSON. By inspecting, one can know ID, scope, type of the driver, containers and their IP’s associated with the network. Also, the subnet, gateway and whether the network supports IPV6 or not can also be known.
Inspecting a container:
An container can be inspected using sudo docker inspect --format='{{json .Config}} <Container_Name_or_ID> which returns the output in JSON format. We can know details of exposed ports, the ID of the container, Image associated with the containers and much more details
Note: The commands starting with sudo may ask the password for the first time. In order to avoid typing password, one can use echo "<Password_of_user_in_System"| sudo –S <Command_to_be_executed_like_root_user>. The -S option allows sudo to read the passwords from standard input
Comments
Post a Comment