Docker服务以退出代码0退出

时间:2019-01-04 20:24:12

标签: python docker flask docker-compose

我有一个要运行的Python Celery泊坞窗服务,但它以状态代码0退出,无论是对所有服务运行docker-compose命令,还是在其他2个启动后仅对芹菜运行。如果我进入烧瓶docker容器并在命令行中运行命令,那么Celery确实会启动。

sh fix_celery_naming.sh只是解决了celery中的命名问题,这使其与Python 3.7不兼容,并且直到Celery的下一个主要版本才准备就绪。

码头工人信息

Containers: 3
 Running: 2
 Paused: 0
 Stopped: 1
Images: 47
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.13.0-46-generic
Operating System: Ubuntu 17.10
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 8.559GiB
Name: ubuntu
ID: NNOD:QGSH:B3HB:PTDT:Y5AG:D5XR:6NH4:CKZS:KV3R:FO3X:7Y3U:IUEN
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: jc
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

docker-compose.yml

version: "3"
services:
  server:
    build:
      context: .
      args:
        GRIP_ENVSET: ${GRIP_ENV}
    volumes:
      - ".:/code"
      - "/tmp:/tmp"
      # Mount the Docker socket so that other Docker images can be started up.
      - "/var/run/docker.sock:/var/run/docker.sock"
    environment:
      - PORT=5000
      - GRIP_ENV=${GRIP_ENV}
      - REDIS_URL=redis://redis
    # Access ports running on the host
    network_mode: host
    #links:
    #  - redis
  redis:
    image: redis
    #restart: on-failure
    container_name: redis
    network_mode: host
    expose:
      - 6379
  celery:
    build: .
    restart: on-failure
    # TODO: Better support for handling Redis not being up yet. (e.g., install Dockerize)
    command: sh fix_celery_naming.sh && celery -A grip_server.celery worker -l info
    volumes:
      - .:/code
    network_mode: host
    depends_on:
      - redis
    tty: true

docker-compose-详细介绍芹菜

compose.config.config.find: Using configuration files: ./docker-compose.yml
WARNING: compose.config.environment.__getitem__: The GRIP_ENV variable is not set. Defaulting to a blank string.
docker.utils.config.find_config_file: Trying paths: ['/home/jc/.docker/config.json', '/home/jc/.dockercfg']
docker.utils.config.find_config_file: Found file at path: /home/jc/.docker/config.json
docker.auth.load_config: Found 'auths' section
docker.auth.parse_auth: Found entry (registry='https://index.docker.io/v1/', username='jc')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/version HTTP/1.1" 200 543
compose.cli.command.get_client: docker-compose version 1.22.0, build f46880fe
docker-py version: 3.4.1
CPython version: 3.6.6
OpenSSL version: OpenSSL 1.1.0f  25 May 2017
compose.cli.command.get_client: Docker base_url: http+docker://localhost
compose.cli.command.get_client: Docker version: Platform={'Name': ''}, Components=[{'Name': 'Engine', 'Version': '18.06.1-ce', 'Details': {'ApiVersion': '1.38', 'Arch': 'amd64', 'BuildTime': '2018-08-21T17:23:27.000000000+00:00', 'Experimental': 'false', 'GitCommit': 'e68fc7a', 'GoVersion': 'go1.10.3', 'KernelVersion': '4.13.0-46-generic', 'MinAPIVersion': '1.12', 'Os': 'linux'}}], Version=18.06.1-ce, ApiVersion=1.38, MinAPIVersion=1.12, GitCommit=e68fc7a, GoVersion=go1.10.3, Os=linux, Arch=amd64, KernelVersion=4.13.0-46-generic, BuildTime=2018-08-21T17:23:27.000000000+00:00
compose.cli.verbose_proxy.proxy_callable: docker info <- ()
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/info HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker info -> {'Architecture': 'x86_64',
 'BridgeNfIp6tables': True,
 'BridgeNfIptables': True,
 'CPUSet': True,
 'CPUShares': True,
 'CgroupDriver': 'cgroupfs',
 'ClusterAdvertise': '',
 'ClusterStore': '',
 'ContainerdCommit': {'Expected': '468a545b9edcd5932818eb9de8e72413e616e86e',
                      'ID': '468a545b9edcd5932818eb9de8e72413e616e86e'},
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={'label': ['com.docker.compose.project=grip-server', 'com.docker.compose.oneoff=False']})
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/json?limit=-1&all=0&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dgrip-server%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 2 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('02d0e7592c5f1069c9085c7d5dc1e9a1c107af484161d2588296619661427e63')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/02d0e7592c5f1069c9085c7d5dc1e9a1c107af484161d2588296619661427e63/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': 'docker-default',
 'Args': [],
 'Config': {'ArgsEscaped': True,
            'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['./start.sh'],
            'Domainname': '',
            'Entrypoint': None,
            'Env': ['PORT=5000',
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('30a3c78300fd6a51c294421050c7cfa1b9a140aaec1286b73390246e99fba2f1')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/30a3c78300fd6a51c294421050c7cfa1b9a140aaec1286b73390246e99fba2f1/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': 'docker-default',
 'Args': ['redis-server'],
 'Config': {'ArgsEscaped': True,
            'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['redis-server'],
            'Domainname': '',
            'Entrypoint': ['docker-entrypoint.sh'],
            'Env': ['affinity:container==64ea18c780ef4cf166b202ed58decccc00ee967c19e52f915b5375b7c9f35799',
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=grip-server', 'com.docker.compose.service=redis', 'com.docker.compose.oneoff=False']})
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/json?limit=-1&all=1&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dgrip-server%22%2C+%22com.docker.compose.service%3Dredis%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 1334
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('30a3c78300fd6a51c294421050c7cfa1b9a140aaec1286b73390246e99fba2f1')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/30a3c78300fd6a51c294421050c7cfa1b9a140aaec1286b73390246e99fba2f1/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': 'docker-default',
 'Args': ['redis-server'],
 'Config': {'ArgsEscaped': True,
            'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['redis-server'],
            'Domainname': '',
            'Entrypoint': ['docker-entrypoint.sh'],
            'Env': ['affinity:container==64ea18c780ef4cf166b202ed58decccc00ee967c19e52f915b5375b7c9f35799',
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=grip-server', 'com.docker.compose.service=celery', 'com.docker.compose.oneoff=False']})
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/json?limit=-1&all=1&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dgrip-server%22%2C+%22com.docker.compose.service%3Dcelery%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 1206
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': 'docker-default',
 'Args': ['fix_celery_naming.sh',
          '&&',
          'celery',
          '-A',
          'grip_server.celery',
          'worker',
          '-l',
          'info'],
 'Config': {'AttachStderr': False,
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('redis')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/images/redis/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'ArgsEscaped': True,
            'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['redis-server'],
            'Domainname': '',
            'Entrypoint': ['docker-entrypoint.sh'],
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('grip-server_celery')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/images/grip-server_celery/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'ArgsEscaped': True,
            'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['./start.sh'],
            'Domainname': '',
            'Entrypoint': None,
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=grip-server', 'com.docker.compose.service=redis', 'com.docker.compose.oneoff=False']})
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/json?limit=-1&all=1&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dgrip-server%22%2C+%22com.docker.compose.service%3Dredis%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 1334
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('redis')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/images/redis/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'ArgsEscaped': True,
            'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['redis-server'],
            'Domainname': '',
            'Entrypoint': ['docker-entrypoint.sh'],
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('30a3c78300fd6a51c294421050c7cfa1b9a140aaec1286b73390246e99fba2f1')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/30a3c78300fd6a51c294421050c7cfa1b9a140aaec1286b73390246e99fba2f1/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': 'docker-default',
 'Args': ['redis-server'],
 'Config': {'ArgsEscaped': True,
            'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['redis-server'],
            'Domainname': '',
            'Entrypoint': ['docker-entrypoint.sh'],
            'Env': ['affinity:container==64ea18c780ef4cf166b202ed58decccc00ee967c19e52f915b5375b7c9f35799',
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={'label': ['com.docker.compose.project=grip-server', 'com.docker.compose.service=celery', 'com.docker.compose.oneoff=False']})
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/json?limit=-1&all=1&size=0&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dgrip-server%22%2C+%22com.docker.compose.service%3Dcelery%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 1206
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_image <- ('grip-server_celery')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/images/grip-server_celery/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_image -> {'Architecture': 'amd64',
 'Author': '',
 'Comment': '',
 'Config': {'ArgsEscaped': True,
            'AttachStderr': False,
            'AttachStdin': False,
            'AttachStdout': False,
            'Cmd': ['./start.sh'],
            'Domainname': '',
            'Entrypoint': None,
...
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': 'docker-default',
 'Args': ['fix_celery_naming.sh',
          '&&',
          'celery',
          '-A',
          'grip_server.celery',
          'worker',
          '-l',
          'info'],
 'Config': {'AttachStderr': False,
...
compose.parallel.feed_queue: Pending: {<Service: redis>, <Service: celery>}
compose.parallel.feed_queue: Starting producer thread for <Service: redis>
compose.service.execute_convergence_plan: redis is up-to-date
compose.parallel.parallel_execute_iter: Finished processing: <Service: redis>
compose.parallel.feed_queue: Pending: {<Service: celery>}
compose.parallel.feed_queue: Starting producer thread for <Service: celery>
Starting grip-server_celery_1 ... 
compose.parallel.feed_queue: Pending: {<Container: grip-server_celery_1 (3a9ed0)>}
compose.parallel.feed_queue: Starting producer thread for <Container: grip-server_celery_1 (3a9ed0)>
compose.cli.verbose_proxy.proxy_callable: docker attach <- ('3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc', stdout=True, stderr=True, stream=True)
urllib3.connectionpool._make_request: http://localhost:None "POST /v1.25/containers/3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc/attach?logs=0&stdout=1&stderr=1&stream=1 HTTP/1.1" 101 0
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc/json HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker attach -> <docker.types.daemon.CancellableStream object at 0x7f38db9b99b0>
compose.cli.verbose_proxy.proxy_callable: docker start <- ('3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc')
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
compose.parallel.feed_queue: Pending: set()
urllib3.connectionpool._make_request: http://localhost:None "POST /v1.25/containers/3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc/start HTTP/1.1" 204 0
compose.cli.verbose_proxy.proxy_callable: docker start -> None
Starting grip-server_celery_1 ... done
compose.parallel.feed_queue: Pending: set()
compose.parallel.parallel_execute_iter: Finished processing: <Service: celery>
compose.parallel.feed_queue: Pending: set()
Attaching to grip-server_celery_1
compose.cli.verbose_proxy.proxy_callable: docker events <- (filters={'label': ['com.docker.compose.project=grip-server', 'com.docker.compose.oneoff=False']}, decode=True)
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/events?filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dgrip-server%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D HTTP/1.1" 200 None
compose.cli.verbose_proxy.proxy_callable: docker events -> <docker.types.daemon.CancellableStream object at 0x7f38dba32710>
compose.cli.verbose_proxy.proxy_callable: docker wait <- ('3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- ('3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc')
urllib3.connectionpool._make_request: http://localhost:None "GET /v1.25/containers/3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc/json HTTP/1.1" 200 None
urllib3.connectionpool._make_request: http://localhost:None "POST /v1.25/containers/3a9ed0271c53166d7a968dfe1e362db75922d82b1bf66be029aa3fcb7c431cfc/wait HTTP/1.1" 200 30
compose.cli.verbose_proxy.proxy_callable: docker wait -> {'Error': None, 'StatusCode': 0}
grip-server_celery_1 exited with code 0
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {'AppArmorProfile': 'docker-default',
 'Args': ['fix_celery_naming.sh',
          '&&',
          'celery',
          '-A',
          'grip_server.celery',
          'worker',
          '-l',
          'info'],
 'Config': {'AttachStderr': False,
...

1 个答案:

答案 0 :(得分:0)

事实证明我需要使用

bash -c "<command>"

能够执行多个命令:

command: bash -c "sh fix_celery_naming.sh && celery -A components.grip_sim_server.server.celery worker"