How to launch a docker with fleet given a dockerfile?

Im just experimenting with coreOS, docker and fleet.
I have the next dockerfile:

FROM ubuntu:14.04

RUN echo "deb precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y install nginx

RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN mkdir /etc/nginx/ssl
ADD default /etc/nginx/sites-available/default


CMD ["nginx"]

I created an image (“nginx-example”) from this file and i can launch the container with:

  • How do I check that a docker host is in swarm mode?
  • How can I create dependent Docker images with Docker Maven plugin?
  • Does use “--no-cache” for automated builds?
  • How to debug the creation of docker container container in Vagrant
  • Deploying a cluster (i.e. MongoDb / ElasticSearch) with Docker and linking to Java Application
  • Docker Hub - Automated build linked to Bitbucket
  • docker run -v /home/core/share:/var/www:rw -p 80:80 -d nginx-example

    Now, I want to launch it with fleet, so I undertand that I have to create a service file and then launching it with fleet.

    So I try to create de service file (nginx1.service):

    ExecStartPre=-/usr/bin/docker kill nginx
    ExecStartPre=-/usr/bin/docker rm nginx
    ExecStartPre=/usr/bin/docker pull nginx-example
    ExecStart=/usr/bin/docker docker run -p 80:80 -d nginx-example  
    ExecStop=/usr/bin/docker stop nginx

    I submmited and started it but when I do:

    fleetctl list-units
    nginx1.service  cbbed2c1.../IP  failed      failed

    And I cant run the web server.
    I think that the problem is in the service file but I dont know how to construct it.
    Thank you.

  • Docker passing environment variable
  • Docker-compose throwing error
  • Error on Docker Pull - “Layer already being pulled by another client”
  • Step by Step Setup Guide to Neo4j Mazerunner in Windows
  • how to implement Sensu Check for checking if Docker Container is running or not
  • Docker container binds to port, but I am unable to ping it
  • 3 Solutions collect form web for “How to launch a docker with fleet given a dockerfile?”

    Here’s a key line in your service file that should get you thinking:

    ExecStartPre=/usr/bin/docker pull nginx-example

    Where do you think is this image being pulled from?
    In order to pull an image, you need to push it somewhere first. The easiest, of course, is DockerHub. You will need to create an account. I’ll leave the exercise of creating the account, repository, and configuring authentication to you, as the documentation is readily available here.

    Now, if you were to just try docker push nginx-example, it would fail, because it needs to be associated with your user account’s namespace, via a tag. For the sake of this answer, let’s assume your account is kimberlybf.

    $ docker tag nginx-example:latest kimberlybf/nginx-example:latest – this will tag your image correctly for pushing to DockerHub.

    $ docker push kimberlybf/nginx-example:latest – this will actually push your image. The image will be public, so don’t put any sensitive data in your configs.

    Then you would modify your Service, and replace the container tags accordingly, also remembering to give your container a name, e.g.:

    ExecStartPre=-/usr/bin/docker kill nginx
    ExecStartPre=-/usr/bin/docker rm nginx
    ExecStartPre=/usr/bin/docker pull kimberlybf/nginx-example:latest
    ExecStart=/usr/bin/docker docker run -p 80:80 -d --name nginx kimberlybf/nginx-example:latest
    ExecStop=/usr/bin/docker stop nginx

    You shouldn’t start your container in daemon-mode (-d):

    “If you are going to modify these units, be sure you don’t copy a
    docker run command that starts a container in detached mode (-d).
    Detached mode won’t start the container as a child of the unit’s pid.
    This will cause the unit to run for just a few seconds and then exit.”

    This works:

    ExecStartPre=/usr/bin/docker pull kimberlybf/nginx-example:latest
    ExecStart=/usr/bin/docker run -p 80:80 -d --name nginx kimberlybf/nginx-example:latest

    And I push my image to DockerHub.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.