简体   繁体   中英

How can I see the options used to start a docker container?

I took over an old PHP project that had an existing infrastructure (servers) up and running. Now I want to move to another provider, but reverse engineering how this is setup is a bit of a mystery. One "mystical" thing about that deployment was the various images and how they related, and the fact that they seemed to share data without any such thing being specified in the the Docker files.

I have now come to realize that it is possible to mount a volume that exists at another container when starting a container using --volumes-from and that is probably how it was done, but I wish I could see the command or options that did this. Is this possible (years later)?

Dockerfiles

Dockerfile.code.yml

This has all the PHP code. Does not seem to do much on its own, apart from logging stuff to stdout.

FROM debian:jessie

COPY . /var/www/myapp/
COPY deploy/parameters.yml.prod /var/www/myapp/app/config/parameters.yml
VOLUME /var/www/myapp/
COPY deploy/myapp-code-start.sh /myapp-code-start.sh
ENTRYPOINT /myapp-code-start.sh

Dockerfile.php-fpm.yml

This is the actual app, but as can be seen from the file, it has no code, which made me wonder how it could work.

FROM php:7.2-fpm

RUN apt update && apt install -y libpq-dev libcurl4-gnutls-dev  libicu-dev
RUN docker-php-ext-install pdo_pgsql pgsql intl pcntl
RUN pecl install redis && docker-php-ext-enable redis
RUN usermod -u 1000 www-data

COPY deploy/php-config/uploads.ini /usr/local/etc/php/conf.d/
COPY deploy/myapp-app-start.sh /myapp-app-start.sh
ENTRYPOINT /myapp-app-start.sh

Docker output

Running containers

root@myapp-app2:~# docker ps
CONTAINER ID        IMAGE                                    COMMAND                  CREATED             STATUS              PORTS                                           NAMES
4551cbfdb140        128.18.125.254:5000/myapp-fpm:latest      "/bin/sh -c /myapp-ap…"   19 months ago       Up 8 months         10.135.17.193:9000->9000/tcp                    root_myapp-fpm_1
8018f756f345        128.18.125.254:5000/myapp-static:latest   "nginx -g 'daemon of…"   19 months ago       Up 8 months         80/tcp, 443/tcp, 10.135.17.193:8080->8080/tcp   root_myapp-static_1
e2d5c3b22e65        128.68.125.254:5000/myapp-cron:latest     "start-cron"             19 months ago       Up 8 months                                                         root_myapp-cron_1
7713d5314f58        128.18.125.254:5000/myapp-code:latest     "/bin/sh -c /myapp-co…"   19 months ago       Up 8 months                                                         root_myapp-code_1
2080da8189fb        redis:3-alpine                           "docker-entrypoint.s…"   19 months ago       Up 8 months         10.135.17.193:6379->6379/tcp                    root_myapp-redis_1

Proof the code and FPM container share a volume

Showing the volumes using this .

root@myapp-app2:~# docker container inspect  -f '{{range .Mounts}}{{.Type}}:{{.Source}}:{{.Destination}}{{println}}{{ end }}'  root_myapp-fpm_1
volume:/var/lib/docker/volumes/6dfeffc141172fc3241c3a8b0d11be2348f41fe22afd74a9fb286e349cf77cbe/_data:/var/www/myapp

root@myapp-app2:~# docker container inspect  -f '{{range .Mounts}}{{.Type}}:{{.Source}}:{{.Destination}}{{println}}{{ end }}'  root_myapp-code_1
volume:/var/lib/docker/volumes/6dfeffc141172fc3241c3a8b0d11be2348f41fe22afd74a9fb286e349cf77cbe/_data:/var/www/myapp

EDIT: added output

Output from docker container inspect

root@myapp-app2:~# docker container inspect root_myapp-fpm_1
[
    {
        "Id": "4551cbfdb140315826d84536ff2339896f48aff4f168253dfe9624f4839571f5",
        "Created": "2020-03-03T11:00:30.24298832Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "/myapp-app-start.sh"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 24657,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-01-19T23:01:06.178494041Z",
            "FinishedAt": "2021-01-19T23:00:56.601585045Z"
        },
        "Image": "sha256:17b8f3c6bb49a1ad358aaffa9e53427bcbc9c72ca38a5ef9ebed92ca9e9e4c30",
        "ResolvConfPath": "/var/lib/docker/containers/4551cbfdb140315826d84536ff2339896f48aff4f168253dfe9624f4839571f5/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/4551cbfdb140315826d84536ff2339896f48aff4f168253dfe9624f4839571f5/hostname",
        "HostsPath": "/var/lib/docker/containers/4551cbfdb140315826d84536ff2339896f48aff4f168253dfe9624f4839571f5/hosts",
        "LogPath": "/var/lib/docker/containers/4551cbfdb140315826d84536ff2339896f48aff4f168253dfe9624f4839571f5/4551cbfdb140315826d84536ff2339896f48aff4f168253dfe9624f4839571f5-json.log",
        "Name": "/root_myapp-fpm_1",
        "RestartCount": 0,
        "Driver": "overlay",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "root_default",
            "PortBindings": {
                "9000/tcp": [
                    {
                        "HostIp": "10.135.17.193",
                        "HostPort": "9000"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "always",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [
                "7713d5314f5812be835f23a69a5038c491b1eed8acbc7c05163db776caf9e294:rw"
            ],
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "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/overlay/6297868c76dc68fed8629f8b17f269e0ac4bed82d6a2e9aec9540f977e9475de/root",
                "MergedDir": "/var/lib/docker/overlay/0e206d71b9812feea939b313258e6647e1b1039c6b10e2d081a005ff5188f306/merged",
                "UpperDir": "/var/lib/docker/overlay/0e206d71b9812feea939b313258e6647e1b1039c6b10e2d081a005ff5188f306/upper",
                "WorkDir": "/var/lib/docker/overlay/0e206d71b9812feea939b313258e6647e1b1039c6b10e2d081a005ff5188f306/work"
            },
            "Name": "overlay"
        },
        "Mounts": [
            {
                "Type": "volume",
                "Name": "6dfeffc141172fc3241c3a8b0d11be2348f41fe22afd74a9fb286e349cf77cbe",
                "Source": "/var/lib/docker/volumes/6dfeffc141172fc3241c3a8b0d11be2348f41fe22afd74a9fb286e349cf77cbe/_data",
                "Destination": "/var/www/myapp",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "4551cbfdb140",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "9000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "PHPIZE_DEPS=autoconf \t\tdpkg-dev \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c",
                "PHP_INI_DIR=/usr/local/etc/php",
                "PHP_EXTRA_CONFIGURE_ARGS=--enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --disable-cgi",
                "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2",
                "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2",
                "PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie",
                "GPG_KEYS=A917B1ECDA84AEC2B568FED6F50ABC807BD5DCD0 528995BFEDFBA7191D46839EF9BA0ADA31CBD89E 1729F83938DA44E27BA0F4D3DBDB397470D12172",
                "PHP_VERSION=7.1.30",
                "PHP_URL=https://www.php.net/get/php-7.1.30.tar.xz/from/this/mirror",
                "PHP_ASC_URL=https://www.php.net/get/php-7.1.30.tar.xz.asc/from/this/mirror",
                "PHP_SHA256=6310599811536dbe87e4bcf212bf93196bdfaff519d0c821e4c0068efd096a7c",
                "PHP_MD5="
            ],
            "Cmd": null,
            "Image": "128.18.125.254:5000/myapp-fpm:latest",
            "Volumes": null,
            "WorkingDir": "/var/www/html",
            "Entrypoint": [
                "/bin/sh",
                "-c",
                "/myapp-app-start.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "com.docker.compose.config-hash": "df8cddcbc8c7112eb8b18b2c1637146b8784597453297142fa56cd69e4ef8ff3",
                "com.docker.compose.container-number": "1",
                "com.docker.compose.oneoff": "False",
                "com.docker.compose.project": "root",
                "com.docker.compose.service": "myapp-fpm",
                "com.docker.compose.version": "1.8.0"
            },
            "StopSignal": "SIGQUIT"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "25b66f536e29814970c16fc0f0518e6f5bb741db37ae4417d70ebff54110c512",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "9000/tcp": [
                    {
                        "HostIp": "10.135.17.193",
                        "HostPort": "9000"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/25b66f536e29",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "root_default": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "myapp-fpm",
                        "4551cbfdb140"
                    ],
                    "NetworkID": "a6dd02493f7b5ba12701c5a73315b56ff3259edaad4ac27b7cbfd1182233d844",
                    "EndpointID": "00cdf1969d3835fd4f3e9b9face8b00c8255707656d285b754a4e19e90ae694e",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.5",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:05",
                    "DriverOpts": null
                }
            }
        }
    }
]

I do see an interesting tidbit in the inspect output:

$ docker container inspect root_myapp-fpm_1  | jq .[0].HostConfig.VolumesFrom
[
  "7713d5314f5812be835f23a69a5038c491b1eed8acbc7c05163db776caf9e294:rw"
]

This seems to imply it was started with --volumes-from 7713d5314f58 , which is using the id of the myapp-code image. I guess this is what I need to recreate the setup kind of , but that volume ID will change with every new deployment, so I needed to find out what started that with volumes_from .

Grepping the source code for volumes_from actually retrieved a docker-compose file:

version: "2"

services:
  myapp-code:
    image: 128.18.125.254:5000/myapp-code:latest
    restart: always
    depends_on:
      - myapp-redis

  myapp-fpm:
    image: 128.18.125.254:5000/myapp-fpm:latest
    restart: always
    ports:
      - "10.135.5.10:9000:9000"
    volumes_from:
      - myapp-code
    depends_on:
      - myapp-code

  myapp-cron:
    image: 128.18.125.254:5000/myapp-cron:latest
    restart: always
    volumes_from:
      - myapp-code
    depends_on:
      - myapp-code

  myapp-static:
    image: 128.18.125.254:5000/myapp-static:latest
    restart: always
    ports:
      - "10.125.5.10:8080:8080"
    volumes_from:
      - myapp-code
    depends_on:
      - myapp-code

  myapp-redis:
    image: redis:3-alpine
    restart: always
    ports:
      - "10.125.1.12:6379:6379"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM