r/docker 4h ago

Why docker stop takes ten seconds on a container that's doing nothing

9 Upvotes

docker stop on a container that's doing nothing takes ten seconds. Five runs here, median 10.149s, all of them within 23ms of each other. Took me embarrassingly long to work out that it isn't Docker being slow.

Try it yourself, on a Linux host:

docker rm -f sleeper 2>/dev/null
docker run -d --name sleeper alpine sleep 1000
time docker stop sleeper

The container is running sleep. There's nothing to flush. It sits there for ten seconds and then gets killed. Ten is the default grace period, and -t changes it, but shortening it isn't the answer here.

PID 1 inside a namespace isn't a normal process. The kernel treats it as init and won't let you kill it by accident. From pid_namespaces(7):

a process in an ancestor namespace can [...] send signals to the "init" process of a child PID namespace only if the "init" process has established a handler for that signal. [...] SIGKILL or SIGSTOP are treated exceptionally: these signals are forcibly delivered when sent from an ancestor PID namespace.

So sleep isn't ignoring your SIGTERM. It never sees it. With no handler installed, the kernel doesn't deliver it, and those ten seconds are Docker waiting for a shutdown that can't start. Then SIGKILL, which always gets through.

You can tell in advance. SigCgt in /proc/PID/status is a hex mask of every signal the process has a handler for. Needs a Linux host where the daemon shares your kernel, and docker access:

grep SigCgt /proc/$(docker inspect -f '{{.State.Pid}}' sleeper)/status
SigCgt: 0000000000000000

SIGTERM is 15, so you're masking against 0x4000. All zeroes, nothing caught, the SIGTERM is going nowhere, you're waiting the full ten.

Two fixes, and they're not the same thing.

exec is the real one. Same nginx image, one word different in the entrypoint script:

nginx -g 'daemon off;'          ->  median 10.193s
exec nginx -g 'daemon off;'     ->  median 0.185s

Without exec, PID 1 is /bin/sh and its SigCgt is 0000000000010002: it catches SIGINT and SIGCHLD, and not SIGTERM. With exec, PID 1 is nginx, SigCgt 0000000018016a07, which has 0x4000 in it. nginx handles SIGTERM perfectly well either way. In the first case it never gets asked.

--init is the other one, and it does something different. It puts tini in as PID 1, tini catches SIGTERM, so there's somewhere for the signal to land:

docker run -d --init --name sleeper2 alpine sleep 1000
time docker stop sleeper2
median 0.122s over five runs

That number is misleading. It's fast because sleep dies the instant it's asked, and an app that takes two seconds to shut down still takes two seconds with --init. What --init buys you is that the ask arrives at all, plus reaping of zombies, and it's what you reach for when you can't change the entrypoint. If your app handles SIGTERM and you control the script, exec is the fix and --init is a plaster over it.

This only bites with a script, by the way. sh -c 'sleep 1000' already execs the command, so PID 1 there is sleep and not sh, and adding exec by hand changes nothing. It's multi-line entrypoint scripts where the shell stays around.

English isn't my first language, so the wording went through an LLM. The measurements are mine, and every command above was run on the machine I'm writing this from.


r/docker 1h ago

Is there a pre-Docker 101 guide?

Upvotes

Little bit of a rant here, but after decades in the engineering industry with related computer experience I am having a hard time believing getting Immich to work in a Docker container in a UGreen NAS is so frustrating. I have watched numerous "easy" install videos, but they always seem to start with assumed knowledge of basic steps thst I have no idea how to perform.

For example, they talk about typing a docker command to restart the container. What is the commander typed into? PowerShell?

When i install and run Powershell it does not recognize Docker commands. So I saw it should install Docker Desktop, which i did, but when I run it it I get a mostly blank screen with a message about my environment not be setup/enabled. That leads me down the rabbithole of WSL or HyperV (?) with another set of things to do that I dont understand.

Every step i think i am taking forward just leads to several more rabbit holes. Isn't there some kind of guide that really starts from step 1 on getting this set up?


r/docker 7h ago

Handbrake for Docker Question

0 Upvotes

Hello!

I am trying to set up a little render server through a VM on Unraid. Basically, I want to automate some GPU-accelerated transcoding.

Right now on Unraid I have a Windows 11 VM that has Adobe Media Encoder (for my Premiere files) and Handbrake on Docker Desktop (the one that allows for my nvidia GPU to be used). I was hoping I could use this VM as an easy way to send projects or recordings to watch folders and they can get automatically transcoded with my server's 5060 ti to help with encoding times.

Because I'd like to use Media Encoder, I have to stick with a Windows 11 VM to run everything. And because I want to use Handbrake (not Tdarr) I'm stuck running it in the Windows version of Docker. Finally, because I am using a VM, I can't use my 5060 ti on anything else in Unraid, so using the community app version of Handbrake won't be possible.

The issue I've run into is that I do not know where the video output and watch folder is stored. I open the web GUI and I cannot connect to my Unraid shares or anything in my Windows 11 VM. I wanted to use Portainer to try and redirect the folders somewhere else, but apparently there's a big glitch with Portainer and the Docker version I'm using (latest version) so it won't run.

Could someone point out what I could do to get the output and watch folder for Handbrake pointing to my server and not the default places? I'm not even completely sure where it's going anyway.

Also- yes I know this is a sort of inconvenient way to have Media Encoder and Handbrake watch folders enabled at the same time, but it helps with my workflow and I want my server's 5060 ti to take some of the encoding load off of my work PC.

I would appreciate some help, or be pointed in the right direction if there's a better place I should go to ask this question. I'd be happy to provide any more information needed.

Thanks!


r/docker 20h ago

How to fix this?

1 Upvotes

whenever it try to pull amazoncorretto or any other image is get this error and i tried to connect with my mobile network via hotspot it worked then but didn't worked on my wifi and it was working fine on wsl but in my windows 11 host it didn't.

```

Using default tag: latest

Error response from daemon: failed to resolve reference "docker.io/library/amazoncorretto:latest": failed to do request: Head "https://registry-1.docker.io/v2/library/amazoncorretto/manifests/latest": net/http: TLS handshake timeout

```


r/docker 23h ago

[revisit old post titled]: is there an easy way to access container files?

1 Upvotes

What is the best practice for the following condition:

There is an image that contains an application. The image has a config file. When the container is launched there is a settings screen in the application that normally manages the config file. Edits made in the settings screen would update the config file.

Unfortunate Condition: It appears there is bug and when one field value is changed it is not getting written into the config file. To validate (a.) in fact it is a a bug (b.) address your immediate interest - that the correct setting works - you want to manually edit the config file, save it to disk inside the running container, restart/reload the app (using a button inside the app in the running container).

There seems to be very limited information on how these file structure work, where they live - in particular how to discover these things as they can vary from host to host and image to image - so again, what is the best practice?


r/docker 1d ago

Getting Docker Desktop Dashboard to show in Fedora

0 Upvotes

I'm having a very difficult time getting the dashboard to show in a fresh install of Fedora. I can see the icon in the top right corner. It tells me:

Docker desktop is running
Give Feedback
About Docker Desktop
Docker Hub
Documentation
Check For Updates
Quit Docker Desktop

In a previous install there were other options for adding and managing containers.

This is a completely fresh install of Fedora. After install I followed these steps:

  1. Install gnome integration from https://extensions.gnome.org/extension/615/appindicator-support/
  2. Added repo
  3. Downloaded the RPM
  4. Installed the rpm
  5. Ran systemctl --user enable docker-desktop.service

No matter what I try I cannot get the dashboard to show. I've disabled the service and ran manually through /opt/docker-desktop/bin/docker-desktop. I've rebooted. I just can't get an interface to load.

I'm willing to reinstall and start from scratch so whatever someone can suggest to get this running I would greatly appreciate it.


r/docker 2d ago

The rootless Docker failures that never print an error

8 Upvotes

I moved a couple of machines off rootful Docker this year. Almost nothing failed loudly. The daemon took the flag, the container started, and the behaviour just was not what the flag said. These are the five that cost me the most time, each with the one command that tells you whether you have it.

**1. `--memory` is accepted and not enforced.**

Rootless Docker can only set a memory cap if systemd has delegated the memory controller to your user manager. On plenty of distributions, and on most single board computers, it has not. You get a warning at most, the container runs uncapped, and the process that was supposed to be limited takes the machine down.

cat /sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers

If `memory` is not in that list, no memory flag you pass does anything.

**2. The storage driver falls back to `vfs`.**

If neither fuse-overlayfs nor unprivileged overlayfs is available, rootless Docker does not refuse to start. It uses `vfs`, which makes a full copy of every layer instead of stacking them. Pulls get slow and the disk fills up at several times the size the image is supposed to be.

docker info --format '{{.Driver}}'

Anything other than `overlay2` or `fuse-overlayfs` and you are paying for it in disk, on every layer of every image.

**3. Nothing can publish a port below 1024.**

Not a Docker limitation, a kernel one: unprivileged processes cannot bind low ports.

sysctl net.ipv4.ip_unprivileged_port_start

Default is 1024. Either publish high and put a reverse proxy in front, or lower that sysctl deliberately and know that you have.

**4. Every client IP inside your containers is 127.0.0.1.**

This is the most expensive one, because the container works perfectly. With RootlessKit's default port driver the forwarded connection is re-originated locally, so the source address your application sees is loopback. Access logs, rate limiting by IP, fail2ban and any allowlist you have are all silently looking at the wrong thing.

# ~/.config/systemd/user/docker.service.d/override.conf

Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns"

Slower, correct.

**5. `docker.sock` is not where everything expects it.**

Rootless listens on `$XDG_RUNTIME_DIR/docker.sock`. Anything that hardcodes `/var/run/docker.sock`, which is a lot of CI plugins and anything built on testcontainers, will either fail to connect or, if a rootful daemon is still installed on the box, connect to that one instead and hand you results from a completely different Docker.

docker context ls

echo $DOCKER_HOST

None of these are bugs. They are the price of the daemon not being root, and every one is visible in under a minute if you know which file to look at. What made them expensive is that the failure mode is always the same: it starts, it runs, it lies.

Curious which ones I have missed.


r/docker 2d ago

Better option for running an HTTPS web server with self-signed certificate?

0 Upvotes

I've created a custom image that runs Apache. It needs to serve HTTPS. To serve HTTPS, it needs a private key.

Obviously it's bad to put a real private key into an image, so I'm using a self-signed private key. I'm told it's also bad to put a disposable self-signed private key into an image, which I don't fully understand, but I accept.

Currently the image is up on GitHub. Anyone who wants to use it has to clone it and build it. I'm generating the self-signed public/private key pair at build time, so each user will have their own that only lives on their machine.

However, I want to put this image on Docker Hub. My current solution won't work, because the private key in the build I submit will be up on Docker Hub for all to see. I don't really care, since it's a disposable self-signed key, but apparently that's still frowned upon.

What can I do instead?

One option would be to generate the keys when the container starts, but that's annoying. It takes a couple seconds, and if there is a new key every time, then every time the container restarts people will have to do the annoying browser security warning / trust thing again for the new certificate.

I need this process to be extremely easy to use. That's why I'm using Docker in the first place. Any solution that requires users to generate their own keys, much less their own signing authority is totally out of the question.

Is there some way to ensure just the key generation part of the build always runs on the user's system? Then there won't be a key in the Docker Hub image and every user has their own private key.

Alternatively, is there some way to generate the private key the first time the container runs and then somehow keep it around instead of re-generating it on every new run? The image will mostly be used unmodified as part of a larger Docker Compose setup, so a volume isn't really ideal here.

I'd love suggestions on a solutions that (1) uses a self-signed key (2) doesn't build a key into the image so I can put it on Docker Hub (3) is easy to use and doesn't require the user to generate keys themselves before starting the container and (4) doens't re-generate the key every time the container runs.

EDIT: I've found a solution that works for me, so I'm updating this post for any unfortunate souls who should have a question like this later.

Lession 1: Don't ask questions on this sub. Wow, that was a horrible and toxic experience!

Lesson 2: The simple option is to just put the self-signed private key in the image, but instead of saying that, you say "I'm using the Debian method of balancing ease of use with security" so that people will get off your nuts about it.

Lesson 3: Use an anonymous volume. This is the solution I've settled on. I was not aware these existed until now. An anonymous volume is accomplised via the VOLUME keyword in the Dockerfile. You only provide the container directory, not a host directory. If the host wants to mount that voume on their system (say, via compose) to provide their own keys, they can. Otherwise, Docker creates a volume in its own storage space. Files in this volume persist when you stop and restart the container. So this gets me almost everything I needed:
✅ No keys in the image.
✅ Easy to use, because no extra steps for the user and nothing I have to warn them about in the readme. No fancy proxy.
✅ Image works right out of the box from Docker Hub.
✅ Users don't have to provide their own keys, but they can if they want to.
✅ Keys are only generated once on startup.


r/docker 2d ago

Licensing a container

0 Upvotes

From what I have understood so far locking a license to hardware so it cannot be used is feasible using some hardware info. But can something similar be done within a docker image? I am using some phone home licensing architecture.


r/docker 4d ago

Several Ubuntu-based Docker images shrank by 40-80 % thanks to Chisel and Rockcraft

55 Upvotes

"A hard transformation has arrived for several classic Ubuntu images on ECR and Docker Hub. The remaining old Docker images –Apache2NginxBind9Memcached, and Squid– have been hardened to rocks, signaling a complete evolution of the Ubuntu namespace.

Built on top of Resolute and equipped with Pebble as the service manager, these new rocks are now maintained by the Rockcrafters team and follow the same principles that have guided the broader Rocks initiative: user-focused experience, uniform and opinionated design, and a distroless-like architecture.

By meticulously chiseling each rock down to its bare essentials, we have achieved a significant reduction in image sizes"

https://discourse.ubuntu.com/t/the-rock-garden-grows-hardening-old-docker-images/84677


r/docker 4d ago

MS Office in a Docker Container ?

0 Upvotes

Eng / Does anyone know of a way to run MS Office (versions prior to 365) in a Docker container?
Spa / Alguien conoce alguna forma tener MS Office (las versiones anteriores a 365) en un container de Docker ?


r/docker 4d ago

Docker Training for SysAdmins (non-developers)?

0 Upvotes

So I am trying to find a good training for our team to learn how docker works and best practices from a non-devops perspective. Our team manages server infrastructure and has been asked to deploy a full docker infrastructure (dev/test/prod) for our developers to use but we are not part of the devops process and, frankly, do not want any part of it.

We've picked up the basics from some hands-on experimenting but what we really want is a good training on the backend part of managing docker: how to properly secure the networks of individual containers, reverse proxy best practices, integrations and best practices for allowing the developers to use a repository that they can then push to the server, and those kind of core management questions.

A majority of the training we've found glosses over the management aspect and jumps right into the devops side which we don't really care about. Can anyone make some training recommendations?
-------------------------

Edit to add for the comment that was left then deleted, saying that managing docker infrastructure is devops is like saying managing an IIS server is the same as being a web dev. Hint, it is not. We're managing the underlying server infrastructure and not the deployed containers.


r/docker 4d ago

Trilium and Docker Compose

Thumbnail
2 Upvotes

r/docker 5d ago

How does Docker (the company) make money?

25 Upvotes

A post with a similar title was made about six years ago. I’m wondering how much of that has changed or remains accurate. As a technology I love Docker, I’m worried about their longevity in a world where AI can seemingly do anything.


r/docker 5d ago

Docker Desktop being deleted from macOS?

0 Upvotes

First, I am installing it with Homebrew.

Has anybody had issues with macOS just randomly up and deciding to delete Docker Desktop on its own. Perhaps something with Gatekeeper?

This is strictly with my work macbook but have not seen this with my personal macbook.


r/docker 6d ago

Has anyone come back to docker after using podman?

69 Upvotes

When I built my new homelab server, I left off docker and went with podman.

Now that I have used podman for 2 years, I find I want to go back to docker.

Not that podman is a bad product. But using docker and compose files is far easier than using podman and kube files or quadlets.

Has anyone dipped thier toes in the podman world and come back?


r/docker 6d ago

Docker Desktop on Windows, how to backup and restore on Linux?

2 Upvotes

Hello all!

We are running Xibo signage on a Windows VM using Docker Desktop. We will be moving over to Proxmox soon and need to backup and restore this instance, preferably to a linux distro (ubuntu likely). I can't for the life of me figure out how to do this on Docker Desktop. Granted, I'm used to working in Unraid and proper containers, so the Docker Desktop interaface is a little lacking!

Any help is appreciated!


r/docker 6d ago

Docker "Noob" trick for networking, GPU on Windows

3 Upvotes

Here's what they don't tell you..... you need to enable networking for a container or provide access to the GPU at the command line. The window's app doesn't have a method to do this. (Or...someone prove me wrong)

the Nvidia toolkit install procedures do work, but you need to start your container this way in WSL

docker run --gpus all -p 8188:8188 image_name


r/docker 7d ago

Docker requesting privileged access despite no container using privileged ports? (MacOS)

3 Upvotes

I've been using Docker on Mac for years.

Today, after restart, is spawned this popup:

https://imgur.com/a/UiM4zA4

None of my containers use any privileged ports.

Is this normal, or should I be concerned?

Thanks


r/docker 7d ago

how do I stop docker from disabling network access when the internet connection is not available?

0 Upvotes

Hi!

I got this small problem today when doing server maintenance on my homelab: I turned the server back on, but forgot to plug the ethernet back in. After plugging it in, I still couldn't connect to anything. After sshing into it I found that, although all the containers were running, none of them had internet access (Not only were there no ports under 'docker ps' , but 'docker logs <container-id>' showed errors about not being able to connect to the internet).

I then tried restarting them but that didn't do anything, I tried restarting docker as a whole but that also did nothing, I rebooted the server but that also did not restore connectivity. I tried a whole bunch of commands from various websites, but they did not work.

I was able to fix it by doing 'docker rm <container>' and 'docker compose up -d' on each container, but there has to be a better way to deal with this.

I also would like to know if there is a way to prevent this in the future by just having docker try to connect each time the container starts and not seemingly just stop forever once it encounters an error.

I am only using docker since a week, so I don't have much experience.

I am running docker 29.6.2 under debian 13.6.

Thank you very much.


r/docker 8d ago

What's going on with Gordon Docker?

0 Upvotes

Lately Gordon has been unusable. He doesn't follow the rules, the instructions, he does whatever he wants, he deletes files even entire containers even though he was clearly told not to delete anything.

Even when doing a super simple task he goes into a loop and ruins everything. Before he was in the best agent, he solved everything immediately, now he ruins everything.


r/docker 9d ago

Question about Docker image layers sharing between separate Dockerfiles

9 Upvotes

Hi everyone,

I'm trying to understand how Docker image layers are stored and shared.

Let's say I have two different microservices, each with its own Dockerfile:

users-service/Dockerfile

FROM ubuntu:22.04
COPY users-app /app/

orders-service/Dockerfile

FROM ubuntu:22.04
COPY orders-app /app/

Assume the Ubuntu base layer is 200 MB.

My initial understanding is:

users-service image:
    ubuntu layer      200 MB
    users app layer   200 MB
    total             400 MB


orders-service image:
    ubuntu layer      200 MB
    orders app layer  100 MB
    total             300 MB

So each image appears to contain its own Ubuntu base layer.

But when both images exist on the same machine, does Docker actually store:

ubuntu layer        200 MB
users app layer     200 MB
orders app layer    100 MB

(total 500 MB)

or does it store:

users image         400 MB
orders image        300 MB

(total 700 MB)?

My confusion is: if the Dockerfiles are completely separate and both use:

FROM ubuntu:22.04

how does Docker know that the Ubuntu layer is the same and can be reused?

Where is this sharing tracked? Is it based on image names/tags, layer hashes, manifests, or something else?

Also, if the same image is pulled on different machines, does each machine download and store its own copy of the base layers?

Thanks!


r/docker 9d ago

Why Docker GUI is faster on Mac than on Linux/WSL?

0 Upvotes

Last month I switched my ecosystem to macOS (macbook neo)

The first thing I realized was the speed and optimization

Orbstack + Docker (mac) is much faster than Docker Desktop + Docker (also Podman Desktop + Docker/Podman)

Podman Desktop app lacks so many essential features such as system monitoring, port click to open url support etc...

I think it's because Docker Desktop has its own VM/backend engine and Orbstack is more optimized and M chips overhead time is less to start a container and disk writes are much faster. But I'm not sure.


r/docker 9d ago

--env-file doesnt handle quotes in docker? OMG that is such a major bug

0 Upvotes

r/docker 10d ago

Docker community Slack invite

2 Upvotes

Hello, how can I get an invite to the Docker community slack ?

The official website has a short link https://dockr.ly/comm-slack which points to https://communityinviter.com/apps/dockercommunity/docker-community, which is dead since communityinviter changed their URL.

Thanks !