Introduction
This is also an article where the main focus is just to be able to access a file exist in a Docker container. So, the Docker container is currently in a running state. Furthermore, the Docker container in this context rely on the Docker Desktop Service. It exist and currently running in the local device using Microsoft Windows as its operating system. Before oging further, the following is the list of the Docker container available :
C:\repository\docker\website\log\httpd>docker container list --all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 382aa9b70218 wordpress:latest "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:8000->80/tcp website-wordpress-1 e89decb01b7d phpmyadmin/phpmyadmin "/docker-entrypoint.…" 12 hours ago Up 11 hours 0.0.0.0:7000->80/tcp website-phpmyadmin-1 2b5997e7d074 mysql:5.7 "docker-entrypoint.s…" 12 hours ago Up 11 hours 3306/tcp, 33060/tcp website-db-1 71bd9ac02bfb httpd:latest "httpd-foreground" 3 days ago Exited (255) 35 hours ago 0.0.0.0:8080->80/tcp docker-image-apache-build-with-docker-compose-apache-1 7fdabbfd9129 mysql "python3" 4 days ago Exited (0) 3 days ago docker-image-build-with-docker-compose-db-1 1eb59b0fef62 wordpress:latest "docker-entrypoint.s…" 5 days ago Exited (0) 13 hours ago wordpress-wordpress-1 937d1783e8f7 mysql:5.7 "docker-entrypoint.s…" 5 days ago Exited (0) 13 hours ago wordpress-db-1 C:\repository\docker\website\log\httpd>
How to Access Apache Log File in a Docker Container
Apparntly, after looking at the output of the command execution in the previous, there are several Docker container available. But not every container is available for further access. In this case, the possible one for further access is only the running one. As in the output of the above command execution it the previous part, there are three running containers. In this context, for accessing the log of the Apache webserver, just access the one running using ‘wordpress’ image. So, the following is the execution of the command for accessing the Apache Webserver’s log file exist in that running container :
C:\repository\docker\website\log\httpd>docker exec -it 382 "docker exec" requires at least 2 arguments. See 'docker exec --help'. Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container C:\repository\docker\website\log\httpd>docker exec -it 382 /bin/bash root@382aa9b70218:/var/www/html# dir index.html readme.html wp-admin wp-config-docker.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php index.php source wp-blog-header.php wp-config-sample.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php license.txt wp-activate.php wp-comments-post.php wp-config.php wp-includes wp-login.php wp-signup.php root@382aa9b70218:/var/www/html# cd /var/log/apache2 root@382aa9b70218:/var/log/apache2# dir access.log error.log other_vhosts_access.log root@382aa9b70218:/var/log/apache2# tail -f access.log 172.18.0.1 - - [05/Jun/2022:23:05:46 +0000] "GET / HTTP/1.1" 302 405 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0" 172.18.0.1 - - [05/Jun/2022:23:05:47 +0000] "GET /wp-admin/install.php HTTP/1.1" 200 4614 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0" 172.18.0.1 - - [05/Jun/2022:23:05:53 +0000] "GET /favicon.ico HTTP/1.1" 302 404 "http://localhost:8000/wp-admin/install.php" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0"
So, the pattern for accessing the Apache Webserver’s log is just by executing the shell program interactively. As in the above command execution, it has the command pattern of ‘docker exec -it container_id /bin/bash’. The container id is ‘382’ is just enough as a reference without having to define it full as it exist in the list as ‘382aa9b70218’. The chosen container available as follow :
C:\repository\docker\website\log\httpd>docker container list --all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 382aa9b70218 wordpress:latest "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:8000->80/tcp website-wordpress-1 ...
The additional parameter of ‘-i’ is an abbrevation of interactively. In other words, execute the container interactively without having to shut the standard input device in the Docker container which is a tty represented by the ‘-t’ parameter. It will create a pseudo TTY as the standard input for further interaction. That is why, it can access the folder where the Apache Webserver log file exist and then check it.