Docker daemon ports: add something like tcp://0.0.0.0:9999 in /etc/docker/daemon.json
It’s about the Docker daemon’s ability to accept commands (like starting/stopping containers, pulling images, etc.) over the network.
forwarding container ports
This is about exposing a specific port of a running container to the host or the outside world, allowing network traffic to reach the service running inside the container.
summary
In summary, setting the Docker daemon to listen on certain TCP ports is about remote management of the Docker engine itself, while forwarding ports for a container is about allowing external access to services running inside that container.
I recently ventured into deploying a service on Google Cloud Run. My goal was straightforward: create a service that fetches webpage titles and captures screenshots of URLs. However, the journey led me into a peculiar bug when I actually used it on Goole Cloud Run.
The Bug
During the development phase, I worked with a python:3.11-slim base image on macOS, and my Dockerfile functioned without a hitch. Here’s a snapshot of the Dockerfile I used:
Yet, upon deploying to Google Cloud Run and initiating the screenshot capture process, I hit a snag:
playwright._impl._api_types.Error: Executable doesn't exist at /home/.cache/ms-playwright/chromium-1084/chrome-linux/chrome
╔═════════════════════════════
║ Looks like Playwright was just installed or updated.
║ Please run the following command to download new browsers:
║
║ playwright install
║
║ <3 Playwright Team
╚═════════════════════════════
Official Playwright Docker Image Saves the Day
Rather than wrestle with the error, I pivoted to an official Docker image of Playwright, and skipped installation of dependency:
The playwright 1.39.0 requires slightly more than 512MB of memory to run on Google Cloud Run. Adjust the memory limit on GCR, as it’s 512 MB by default.
Conclusion
Use the official Docker image to save time, or specify the PLAYWRIGHT_BROWSERS_PATH environment variable on a supported linux docker image.
When building Docker images, it is common to configure Git within the image using commands like git config --global user.name and git config --global user.email. These commands update the global Git configuration for the user during the image build process. However, when running git commit inside a container that is spawned from the image, you may encounter a “please tell me who you are” error. This error occurs because the Git configuration set during the build process does not persist in the container.
The Issue
The git config --global command updates the global Git configuration for the user running the command. By default, the configuration is stored in a .gitconfig file located in the home directory of the user. When you add the git config commands to your Dockerfile, they only affect the image build process and do not persist when a container is created.
Solution Methods
Method 1: Set Git Config at Runtime
One way to resolve this issue is by setting the Git configuration within the container at runtime. This can be done manually or by adding the commands to a startup script. For example, you can run the following commands when starting the container:
By setting the Git configuration at runtime, it ensures that the configuration is applied consistently whenever a container is started.
Method 2: Copy a Prepared .gitconfig File
Another approach is to prepare a .gitconfig file on your host system with the desired settings and then copy it into the Docker image. This method allows you to define the Git configuration outside of the Docker build process.
To do this, create a .gitconfig file on your host system with the desired Git settings. For example:
[user]name=Your Name
email = email@example.com
Next, include the following line in your Dockerfile:
COPY .gitconfig /root/.gitconfig
This line copies the .gitconfig file from the host system into the /root/.gitconfig path within the image. When a container is created from the image, it will include the copied .gitconfig file, ensuring that the Git configuration is persisted.
Conclusion
When using Git within Docker containers, it is important to ensure that the Git configuration persists across container runs. This can be achieved by setting the Git configuration at runtime or by copying a prepared .gitconfig file into the container. By following these approaches, you can avoid the “please tell me who you are” error and have consistent Git configurations within your Docker containers.