Open main menu

Changes

3,802 bytes added ,  18:12, 19 December 2023
→‎Docker in Docker: more security focus
*https://docs.docker.com/develop/
*https://docs.docker.com/engine/
*https://docs.docker.com/engine/install/
Docker also supports containers storing files in-memory on the host machine. Such files are not persisted. If you’re running Docker on Linux, tmpfs mount is used to store files in the host’s system memory. If you’re running Docker on Windows, named pipe is used to store files in the host’s system memory.</blockquote><br />
That is all you need to know <ref>Not really. In practice you need to fully understand how the volumes and mounts work to avoid very common pitfalls like the [https://www.joyfulbikeshedding.com/blog/2021-03-15-docker-and-the-host-filesystem-owner-matching-problem.html '''host filesystem owner matching problem'''] In a nutshell, the best approach is to run your container with a UID/GID that matches the host's UID/GID. It can be hard to implement while addressing all caveats. Hongli Lai [https://www.joyfulbikeshedding.com/blog/2023-04-20-cure-docker-volume-permission-pains-with-matchhostfsowner.html wrote a tool to solve this] ([https://github.com/FooBarWidget/matchhostfsowner MatchHostFSOwner])</ref> about Docker when it comes to sharing files between the host and the container.
Volumes are the preferred way to [https://docs.docker.com/get-started/05_persisting_data/ persist data in Docker containers] and services.
Bitnami has a [https://github.com/bitnami/bitnami-docker-mediawiki Docker Image for MediaWiki] Don't use Bitnami. You will thank me later.
== Security ==
Docker apparently doesn't respect your host firewall by default - leading to the potential for a gaping security hole. This has been a [https://github.com/docker/for-linux/issues/690 reported bug since 2018]. One fix is to [https://www.smarthomebeginner.com/traefik-docker-security-best-practices/#10_Change_DOCKER_OPTS_to_Respect_IP_Table_Firewall set the DOCKER_OPTS] configuration parameter. Another is to add a jump rule to UFW. The bug report links to docs and multiple references.
==Future ReadingDocker Downsides ==One major negative to the system architecture of Docker is that it relies on a server daemon. **Unlike** [[Podman]], Docker's Engine can use up 4GB of RAM just sitting idle.A similar thing happens with WSL2 on Windows <ref>https://news.ycombinator.com/item?id=26897095</ref>
#The compose application model https://docs.docker.com/compose/compose-file/02-model/#Understand how moby [https://github.com/moby/buildkit buildkit] is integrated with [https://github.com/docker/buildx buildx] (or docker) and use it.#Interesting read about docker commit https://adamtheautomator.com/docker-commit/== Future Reading ==
# The compose application model https://docs.docker.com/compose/compose-file/02-model/
# Understand how moby [https://github.com/moby/buildkit buildkit] is integrated with [https://github.com/docker/buildx buildx] (or docker) and use it.
# Interesting read about docker commit https://adamtheautomator.com/docker-commit/
Inspect your running container based on it's container name: docker inspect $(docker container ls | awk '/app2/ {print $1}')
 
== Docker in Docker ==
Before you get 'fancy' with Docker, be sure to read and understand the Security best practices for Docker
https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html
 
Containers (unlike virtual machines) share the kernel with the host, therefore kernel exploits executed inside a container will directly hit the host kernel. For example, a kernel privilege escalation exploit ([https://github.com/scumjr/dirtycow-vdso like Dirty COW]) executed inside a well-insulated container will result in root access in the host.
 
That said, https://devopscube.com/run-docker-in-docker/ presents several use cases and techniques for DinD.
 
=== Docker In Docker ===
The DinD method is '''Docker inside Docker'''. Docker provides a special Docker container with the <tt>dind</tt> tag which is pre-configured to run Docker inside the container image.
 
An example of Docker In Docker would be running Docker inside a Docker image on Windows Subsystem for Linux (WSL)
 
# Install Docker Desktop for Windows.
# Enable the WSL 2 backend in Docker Desktop settings.
# Set WSL 2 as your default version: <code>wsl --set-default-version 2</code> in PowerShell.
# Install a Linux distribution from the Microsoft Store (Ubuntu, for example).
# Open your Linux distribution (WSL 2 instance), and install Docker.
# Add your user to the Docker group to manage Docker as a non-root user: <code>sudo usermod -aG docker $USER</code>.
# Test Docker with: <code>docker run hello-world</code>.
 
Running Docker inside Docker can lead to some security and functionality issues. It's often better to use the Docker daemon of the host machine. You can do this by mounting the Docker socket from the host into the container. See the "Docker outside of Docker" section.
 
=== Docker outside of Docker ===
The DooD method, '''Docker outside of Docker,''' uses the docker socket of the host system from inside containers by mounting the host socket into the filesystem of the container.
 
Try curl to see how different processes can communicate through a socket on the same host: <syntaxhighlight lang="bash">
curl --unix-socket /var/run/docker.sock http://localhost/version
</syntaxhighlight>
 
While there are benefits to using the DooD method, you are giving your containers full control over the Docker daemon, which effectively is root on the host system. To mitigate these risks, again refer to [https://docs.docker.com/engine/security/ the Security model of Docker], the [https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html Docker Security Cheat Sheet from OWASP] and be sure to run your Docker daemon as an unprivileged user.
 
 
=== For security, use Nestybox Sysbox runtime ===
See https://github.com/nestybox/sysbox<nowiki/>
{{References}}
[[Category:Virtualization]]
[[Category:DevOps]]
[[Category:Kubernetes]]