How to run docker with float using docker file?

I'm just experimenting with coreOS, docker and navy. I have the following docker file:

FROM ubuntu:14.04

RUN echo "deb http://archive.ubuntu.com/ubuntu 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

EXPOSE 80

CMD ["nginx"]

      

I have created an image ("nginx-example") from this file and I can start the container with

docker run -v /home/core/share:/var/www:rw -p 80:80 -d nginx-example

      

Now I want to start it with float, so I commit to create a service file and then start it with float.

So, I'm trying to create a service file (nginx1.service):

[Unit]
Description=MyTry
After=docker.service
Requires=docker.service

[Service]
TimeoutStartSec=0
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 subdued and started it, but when I do:

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

      

And I am unable to start the web server. I think the problem is in the service file, but I don't know how to build it. Thank.

+3


source to share


3 answers


Here is the key line in your service file that will make you think:

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

      

Where do you think this image is drawn from?
To pull an image, you need to first click it somewhere. The simplest is of course DockerHub . You will need to create an account. I'll leave it to you to create an account, a repository, and set up authentication, as the documentation is readily available here .

Now if you just try it docker push nginx-example

, it will fail because it must be associated with your user account 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 correctly mark your image for pushing to DockerHub.

$ docker push kimberlybf/nginx-example:latest

- it will actually nudge your image. The image will be publicly available, so do not put any sensitive data in your configs.

Then you will change Service

yours and replace the container tags accordingly, also remember to give your container a name like:

[Service]
TimeoutStartSec=0
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

      

0


source


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

"If you are going to modify these devices, make sure you don't copy the docker startup command, which starts the container in a separate mode (-d). The separate mode does not start the container as a child of the device pid. This will cause the device to work. just a few seconds and then it exits. "



https://coreos.com/docs/launching-containers/launching/fleet-example-deployment/#service-files

+1


source


It works:

[Service]
TimeoutStartSec=0
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.

+1


source







All Articles