Custom nginx container exits immediately when part of docker-compose

后端 未结 4 1239
自闭症患者
自闭症患者 2021-01-30 17:34

I\'m trying to learn how to use docker compose with a simple setup of an nginx container that reroutes requests to a ghost container. I\'m using the standard ghost image but hav

相关标签:
4条回答
  • 2021-01-30 18:06

    I figured out what it was. I needed to name the nginx part of my composition something other than 'nginx' . I'm not sure if it's because there is already an nginx image or if it is something else, but changing it made it work properly.

    By changing my compose file to:

    ghost:
     expose:
       - "2368"
     image: ghost
    
    mything:
      # image: nginx
      build: ./nginx
      ports:
        - "80:80"
        - "443:443"
      links:
       - ghost
    

    I was able to get it to work. An indicator was that when the name changed, I actually saw the build process output for my container. If anyone knows exactly why the naming needs to be that way, I'd love to know.

    0 讨论(0)
  • 2021-01-30 18:11

    The CMD in your Dockerfile should start a process which needs to run in foreground. The command service nginx start runs the process in deamon mode and thus your container exits cleanly because the service command exits.

    Use the following CMD ["nginx", "-g", "daemon off;"] to start nginx (taken from official image) and it should work correctly.

    0 讨论(0)
  • 2021-01-30 18:15

    Just ran into this same issue, and the initial fix was to change the name of the service in docker-compose.yml.

    This worked, but the reason it worked is because Docker-compose caches the build & ties it to the service name. Every docker-compose up after the first one just uses what it built before, so any changes you make to the Dockerfile, or that section of the docker-compose.yml are basically ignored.

    When you (and I) changed the service name, it triggered a new build since that service name hasn't been tagged before.

    The real solution is to do a: docker-compose build to rebuild the image (followed by a docker-compose up). Their documentation doesn't really emphasize this issue.

    0 讨论(0)
  • 2021-01-30 18:16

    You can also add a

    tty: true
    

    to the service in your docker-compose.yml:

    webserver:
        build: .
        volumes:
            - "./src:/var/www/html"
        ports:
            - 8080:80
        depends_on:
            - aap-mysql
        tty: true
    

    and it should stay running after

    docker-compose up
    
    0 讨论(0)
提交回复
热议问题