• 因为要重装系统,所以镜像是windows系统里使用docker export命令导出的,然后重装完系统、装docker,用docker import导回去
  • 环境说明:windows系统运行docker
  • 提前说明:我这种情况以及解决方法不一定所有人都合适,仅供参考
D:\接口平台\interface>docker run -d -v D:\接口平台\interface:/var/www/interface -p 9000:9000 --name php tw-jiekou-php:v1
docker: Error response from daemon: No command specified.
See 'docker run --help'.
  • 查看镜像信息,发现config里的cmd为null
docker inspect 999600f2d1e7(容器id)
[
    {
        "Id": "sha256:999600f2d1e7fc9ef114384c23da96c7eb3186280d62c792b6bfe04e91b836a9",
        "RepoTags": [
            "tw-jiekou-php:v1"
        ],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "Imported from -",
        "Created": "2021-12-15T04:00:19.509783Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "20.10.8",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null, // **此处cmd为null**
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
		省略......
  • 因此我们在运行容器的时候需要在命令后面加上/bin/bash
  • 命令说明:因为用的phpstorm编辑器的命令行,所以windows环境下我也用/bin/bash(同linux),如果是windows的cmd需要在开头加上winpty,结尾换成bash(没记错的话)
docker run -d -v D:\接口平台\interface:/var/www/interface -p 9000:9000 --name php tw-jiekou-php:v1 /bin/bash
  • 用docker ps -a查看所有容器,发现php并没有启动,哪怕运行命令里加了-d
D:\接口平台\interface>docker ps -a
CONTAINER ID   IMAGE              COMMAND                  CREATED         STATUS                     PORTS                                       NAMES
c0f2fd220cfa   tw-jiekou-php:v1   "/bin/bash"              5 minutes ago   Exited (0) 5 minutes ago                                               php
876924cf1bd3   redis              "docker-entrypoint.s…"   29 hours ago    Up 5 hours                 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   redis

  • 对比检查后发现COMMAND里少docker-php-entrypoint php-fpm导致php没有启动(ps:学的比较浅,并不知道这个的作用,如果有人知道可以留言教我一波哈)
D:\接口平台\interface>docker run -d -v D:\接口平台\interface:/var/www/interface -p 9000:9000 --name php tw-jiekou-php:v1 /bin/bash docker-php-entrypoint php-fpm
faa98dd2115782fe5f4cb8d3510baa9b1c3df8aeda2cf26dc69cc36dbd5a54d6

D:\接口平台\interface>docker ps -a
CONTAINER ID   IMAGE              COMMAND                  CREATED         STATUS         PORTS                                       NAMES
faa98dd21157   tw-jiekou-php:v1   "/bin/bash docker-ph…"   5 seconds ago   Up 3 seconds   0.0.0.0:9000->9000/tcp, :::9000->9000/tcp   php
876924cf1bd3   redis              "docker-entrypoint.s…"   29 hours ago    Up 5 hours     0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   redis

# docker ps -a --no-trunc 展示全部容器信息
D:\接口平台\interface>docker ps -a --no-trunc
CONTAINER ID                                                       IMAGE              COMMAND                                                                 CREATED          STATUS          PORTS                                       NAMES
faa98dd2115782fe5f4cb8d3510baa9b1c3df8aeda2cf26dc69cc36dbd5a54d6   tw-jiekou-php:v1   "/bin/bash docker-php-entrypoint php-fpm"                               28 minutes ago   Up 28 minutes   0.0.0.0:9000->9000/tcp, :::9000->9000/tcp   nginx/php,php
876924cf1bd333a31967dfa9ace19d750b012dc8b88d7130a374efff65d9ec76   redis              "docker-entrypoint.sh redis-server /data/redis.conf --appendonly yes"   29 hours ago     Up 6 hours      0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   redis
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐