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:

  • In Docker, what's the difference between a container and an image?
  • What is the purpose of VOLUME in Dockerfile
  • Is there a performance impact to having docker containers with different OS base boxes?
  • specifying network ip docker
  • Remote Node.js typescript debugging in WebStorm
  • How to integrate Capistrano with Docker for deployment?
  • 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.

  • How to start an LXC container inside a Docker container
  • Docker : Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  • Docker apache2 will not consider new 000-default.conf
  • rg.apache.spark.SparkException: Invalid master URL: spark://tasks.501393358-spark-master:7077
  • Docker, how to deal with ssh keys, known_hosts and authorized_keys
  • How do I use the “git-like” capabilities of Docker?
  • 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.