0

我正在尝试运行 chrome 容器。

这对我有用:

[practice]$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome
b7d63881869721fe66a4f00de4be7a3bfb8e922410776a7c35f827bfd08f9455
[practice]$ docker container ls
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                    NAMES
b7d638818697        selenium/standalone-chrome   "/opt/bin/entry_poin…"   22 seconds ago      Up 22 seconds       0.0.0.0:4444->4444/tcp   lucid_sammet

但我的要求是在我的容器内有一个额外的包,所以我创建了一个 DockerFile

FROM selenium/standalone-chrome 

FROM node:latest
RUN npm install --save @ffmpeg-installer/ffmpeg

并使用以下方法创建了一个构建:

[practice]$ docker build -t mychrome:1.0 .
Sending build context to Docker daemon  15.34MB
Step 1/3 : FROM selenium/standalone-chrome
 ---> c84475653f71
Step 2/3 : FROM node:latest
 ---> a511eb5c14ec
Step 3/3 : RUN npm install --save @ffmpeg-installer/ffmpeg
 ---> Using cache
 ---> 2d04ced6065c
Successfully built 2d04ced6065c
Successfully tagged mychrome:1.0

但是当我创建容器时,它会被自己杀死。

[practice]$ docker run -d -p 4444:4444 -v /dev/shm:/dev/shm mychrome:1.0
1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211
[practice]$ docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

这是码头工人检查:

[practice]$ docker container ls -a
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS                           PORTS               NAMES
1e6416ff6d23        mychrome:1.0                  "docker-entrypoint.s…"   2 minutes ago       Exited (0) 2 minutes ago                             compassionate_panini
b2dcd66a3f97        mychrome:1.0                  "docker-entrypoint.s…"   2 minutes ago       Created                                              elegant_mcc
[practice]$ docker inspect 1e6416ff6d23
[
    {
        "Id": "1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211",
        "Created": "2020-05-09T06:51:21.8510204Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "node"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2020-05-09T06:51:22.1525569Z",
            "FinishedAt": "2020-05-09T06:51:22.331137Z"
        },
        "Image": "sha256:2d04ced6065c32a7f1e2d3d28988302b7e762533f7964b8bcbe344f05ba65fdc",
        "ResolvConfPath": "/var/lib/docker/containers/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211/hostname",
        "HostsPath": "/var/lib/docker/containers/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211/hosts",
        "LogPath": "/var/lib/docker/containers/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211/1e6416ff6d232cc7fb1990ac5ae425af72d6456ec2a94d6b575431edb9e04211-json.log",
        "Name": "/compassionate_panini",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/dev/shm:/dev/shm"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "4444/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "4444"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "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": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "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/55f20b215a1ff36c8ebb1dff18cac13e9b0a8fb30d5e81a7bd98c8d259a53cde-init/diff:/var/lib/docker/overlay2/d9ffce8fb048fc9b3f06d8bf9722848e1c634fa62c6cddf3b81c8fd69f168d15/diff:/var/lib/docker/overlay2/ac6f63198e071b53404e7f46a18e442fbb3940bd1ab33689b14c3cefd0cec63f/diff:/var/lib/docker/overlay2/27e169d3a5ecd1eb5a1a169fd295b8bcb01c03bb0de80609bf1f8b807a922ab0/diff:/var/lib/docker/overlay2/1bc8d050ec3936a42bfc5274d3857b0b507245798226de02db185a4bed2ee505/diff:/var/lib/docker/overlay2/e51f7d0d89f2480c94a247f4fece58ba82ecf0139b3d066a7154f74ea196fb67/diff:/var/lib/docker/overlay2/6a241e18bf0fed51affe0f856b9a685d81db7ecd3b5e73754ce94d3a77e66173/diff:/var/lib/docker/overlay2/8c2950f8c31da7a939c93f9fe187c52eea8317a4b64ee2c3b75b09e2db924ce5/diff:/var/lib/docker/overlay2/1fce7515c1871f43e30f3761ef340c8a85fc7de0c3902299db206a2ba0461bd3/diff:/var/lib/docker/overlay2/84d7667120601df8ff0c8187d350fe3700611a7eb9294dde6d6ce8343150551d/diff:/var/lib/docker/overlay2/26c37b434064f095df1114f55e37487094c1efcd8c4bb7b40507da171553210c/diff",
                "MergedDir": "/var/lib/docker/overlay2/55f20b215a1ff36c8ebb1dff18cac13e9b0a8fb30d5e81a7bd98c8d259a53cde/merged",
                "UpperDir": "/var/lib/docker/overlay2/55f20b215a1ff36c8ebb1dff18cac13e9b0a8fb30d5e81a7bd98c8d259a53cde/diff",
                "WorkDir": "/var/lib/docker/overlay2/55f20b215a1ff36c8ebb1dff18cac13e9b0a8fb30d5e81a7bd98c8d259a53cde/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/dev/shm",
                "Destination": "/dev/shm",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "1e6416ff6d23",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "4444/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NODE_VERSION=14.1.0",
                "YARN_VERSION=1.22.4"
            ],
            "Cmd": [
                "node"
            ],
            "Image": "mychrome:1.0",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "c14a931bf5ad40900b83e8f1ee770d270765af1ff181ff610ed2b564d12e3f13",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/c14a931bf5ad",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "51bc10f592d1c05978822f1f5c8a108dffa0581fd6c639e73984bf0760831564",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]

请让我这里有什么问题。

4

1 回答 1

0

通过使用这个 dockerfile 让它工作:

FROM node:latest AS node_base

RUN echo "NODE Version:" && node --version
RUN echo "NPM Version:" && npm --version
RUN npm install --save @ffmpeg-installer/ffmpeg
RUN echo "NPM Modules:" && npm ls


FROM selenium/standalone-chrome

USER root

COPY --from=node_base . .

RUN echo "NPM Modules:" && npm ls

RUN echo "file ends..."
于 2020-05-09T16:28:20.093 回答