/bin/sh not working
PackElend opened this issue · comments
I tried to run /bin/sh
inside the whoami
container but it fails but according to inspect
it should work.
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"EXPOSE 80"
],
but
root@Ubuntu18:/opt/10_docker-compose-files# docker exec -it whoami /bin/sh
OCI runtime exec failed: exec failed: container_linux.go:346: starting container process caused "exec: \"/bin/sh\": stat /bin/sh: no such file or directory": unknown
docker inspect containous/whoami
root@Ubuntu18:/opt/10_docker-compose-files# docker inspect containous/whoami
[
{
"Id": "sha256:5e3337d43760321f87cb6581717817b5c6ee7e2592329e313016fc4fd84a86bd",
"RepoTags": [
"containous/whoami:latest"
],
"RepoDigests": [
"containous/whoami@sha256:c0d68a0f9acde95c5214bd057fd3ff1c871b2ef12dae2a9e2d2a3240fdd9214b"
],
"Parent": "",
"Comment": "",
"Created": "2019-10-06T18:11:08.622523248Z",
"Container": "ec87338134f236d64150373d41f531a413773ffdd7f0486765e9bd8d0730ac03",
"ContainerConfig": {
"Hostname": "ec87338134f2",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"EXPOSE 80"
],
"Image": "sha256:d4ecbfb4906dbda7e810a8607a2bf01dc559b25886a4969a9748578a7b5a0015",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/whoami"
],
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "18.06.0-ce",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": null,
"Image": "sha256:d4ecbfb4906dbda7e810a8607a2bf01dc559b25886a4969a9748578a7b5a0015",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/whoami"
],
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 7400843,
"VirtualSize": 7400843,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/2e724f15baf2d09dbcc6be8c2d990cd58eca55ef347a4c1fb292ec6ed377aea6/diff:/var/lib/docker/overlay2/4489560a5dee35328a1aee14ed17db4cf467f2197b79026b97468bbbf43b0aee/diff",
"MergedDir": "/var/lib/docker/overlay2/fff4074098ba0241d26a26612d2c2cab5d37093a4b131d8590a1923f7caee791/merged",
"UpperDir": "/var/lib/docker/overlay2/fff4074098ba0241d26a26612d2c2cab5d37093a4b131d8590a1923f7caee791/diff",
"WorkDir": "/var/lib/docker/overlay2/fff4074098ba0241d26a26612d2c2cab5d37093a4b131d8590a1923f7caee791/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:20790004c269fde57cd2f3a61a0d172326866d2bf10743ab78401a988e5c76f2",
"sha256:d929d3d3315f88e09d29dc77d991af280d7d2aa5c6974479a6d3c97f4c5dff68",
"sha256:315baccbc30305bd711a433b73a999942c4029688cefbcbb4a3a65aa73697454"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
docker inspect whoami
root@Ubuntu18:/opt/10_docker-compose-files# docker inspect whoami
[
{
"Id": "957a7d1305ce3d627db94a552765f822c0695cb52a16fc7a768cf9baf638b4ef",
"Created": "2020-01-19T13:04:09.405590632Z",
"Path": "/whoami",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 13422,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-01-19T13:04:11.163418421Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:5e3337d43760321f87cb6581717817b5c6ee7e2592329e313016fc4fd84a86bd",
"ResolvConfPath": "/var/lib/docker/containers/957a7d1305ce3d627db94a552765f822c0695cb52a16fc7a768cf9baf638b4ef/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/957a7d1305ce3d627db94a552765f822c0695cb52a16fc7a768cf9baf638b4ef/hostname",
"HostsPath": "/var/lib/docker/containers/957a7d1305ce3d627db94a552765f822c0695cb52a16fc7a768cf9baf638b4ef/hosts",
"LogPath": "/var/lib/docker/containers/957a7d1305ce3d627db94a552765f822c0695cb52a16fc7a768cf9baf638b4ef/957a7d1305ce3d627db94a552765f822c0695cb52a16fc7a768cf9baf638b4ef-json.log",
"Name": "/whoami_viaSubdomain",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": [],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "bridge_proxy_traefikv2",
"PortBindings": {},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/9b2e0fff9935c7687fbf10c8b912c9f22ea7fa2064a8efa43d3f3fb0b5d994bc-init/diff:/var/lib/docker/overlay2/fff4074098ba0241d26a26612d2c2cab5d37093a4b131d8590a1923f7caee791/diff:/var/lib/docker/overlay2/2e724f15baf2d09dbcc6be8c2d990cd58eca55ef347a4c1fb292ec6ed377aea6/diff:/var/lib/docker/overlay2/4489560a5dee35328a1aee14ed17db4cf467f2197b79026b97468bbbf43b0aee/diff",
"MergedDir": "/var/lib/docker/overlay2/9b2e0fff9935c7687fbf10c8b912c9f22ea7fa2064a8efa43d3f3fb0b5d994bc/merged",
"UpperDir": "/var/lib/docker/overlay2/9b2e0fff9935c7687fbf10c8b912c9f22ea7fa2064a8efa43d3f3fb0b5d994bc/diff",
"WorkDir": "/var/lib/docker/overlay2/9b2e0fff9935c7687fbf10c8b912c9f22ea7fa2064a8efa43d3f3fb0b5d994bc/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "957a7d1305ce",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": null,
"Image": "containous/whoami",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/whoami"
],
"OnBuild": null,
"Labels": {
"app_name": "whoami",
"com.docker.compose.config-hash": "dc97c6a2ec70af4a09f621592daf243da18177ff28f0d78a27045a16ec050374",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "10_docker-compose-files",
"com.docker.compose.service": "whoami",
"com.docker.compose.version": "1.24.1",
"traefik.docker.network": "bridge_proxy_traefikv2",
"traefik.enable": "true",
"traefik.http.routers.whoami_viaSubdomain.entrypoints": "web@80",
"traefik.http.routers.whoami_viaSubdomain.rule": "Host(`whoami.fairbnb.community`)"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "d2055d08f79afc81451f2f621d3e4609c1ca1bc6fcf25903ed4125c720e2091e",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": null
},
"SandboxKey": "/var/run/docker/netns/d2055d08f79a",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge_proxy_traefikv2": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"whoami_viaSubdomain",
"957a7d1305ce"
],
"NetworkID": "bb2fe97e47e9add779bc36e981bc5786b545e9a766fa5ff6e5f8ff89492dd925",
"EndpointID": "2093215e8004271a5155097e7786d8abf00afbb69892066770dd73fc997129dd",
"Gateway": "172.20.0.1",
"IPAddress": "172.20.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:14:00:04",
"DriverOpts": null
}
}
}
}
]
Hello,
the whoami container is based on a FROM SCRATCH
image, so there is no shell.
thx for the quick question but could you explain in more detail.
I'm a bit lost with the whoami image.
According to whoami's dockerfile is build FROM SCRATCH using golang:1-Alpine what is the latest stable images according to golang simple tags.
On top of this to go modules are installed go.mod
and go.sum
, that's it.
In Image Variants, it is said that is on the popular Alpine Linux project, available in the alpine official image.
Everywhere is said that Alpine
comes with /bash/sh
:
- containous/traefik-library-image#28
- https://stackoverflow.com/questions/40944479/how-to-use-bash-with-an-alpine-based-docker-image
- http://containertutorials.com/alpine/get_started.html
...
Is another alpine image necessary to have the shell included and only the very base image, that only includes the file system without any binaries? That is how I understand Creating a Docker Image from Scratch – Linux Hint (plus Create a base image | Docker Documentation).
This assumption is challenged by
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"EXPOSE 80"
],
in the whoami image.
I reckon the explanation is given in:
- bash - Starting container process caused "exec: "/bin/sh": stat /bin/sh: no such file or directory": unknown - Stack Overflow
- bash - Starting container process caused "exec: "/bin/sh": stat /bin/sh: no such file or directory": unknown - Stack Overflow
- docker - Error: Cannot Start Container: stat /bin/sh: no such file or directory" - Stack Overflow
but I don't fully get it. Besides this, they also mentioned there, that Alpine comes with /bin/sh
.
Moreover, I don't find anything that would indicate that Cmd
in the image gets overridden as mentioned in linux - Starting a shell in the Docker Alpine container - Stack Overflow.
Last but not least, I'm still sure that I could start a shell
once in the whoami
container but I cannot remember how and this is driving me nuts.
May I don't see the woods for the tree but some help is welcome.
BACKGROUND
I want to mount BasicAuth - Traefik usersFile
in the container but I get occasionally the error message that the file cannot be found.
Without a shell
, I can hardly troubleshoot.
- The whoami Dockerfile is a multistage build file:
- stage 1: build the binary
- stage 2: build the image
https://github.com/containous/whoami/blob/9bf5b44f24ad03c76e9f7b632736795f5314902a/Dockerfile#L19
-
The whoami image is not related to the traefik image
-
The file used by the basic auth must be in the Traefik container.
1. The whoami image is not related to the traefik image
that is clear
2\. The file used by the basic auth must be in the Traefik container.
but I want to add BasicAuth
to whoami
what works when I do
- traefik.http.middlewares.whoami_auth.basicauth.users=user:$$2y$$15$$GP95en
what may made traefik/traefik#4791 (comment) even worse.
usersFile
and users
are not the same thing:
usersFile
reference a file in the Traefik containerusers
is just a string.
usersFile
reference a file in the Traefik container
I assumed it references to a file in the labelled container.
So if I would like to use unique usersFile
per container managed by Traefik, each file has to be mounted into the Traefik container, hasn't it?
yes, the users files must be inside the Traefik container.
the docs may be improved to make this clearer 😃