dagda1
dagda1

Reputation: 28920

brief overview of current docker workflow with nginx

I have currently installed docker 1.9 and I want to create and work on a nginx instance locally on osx and deploy the nginx instance to ubuntu.

All I can find online are conflicting posts from earlier versions of docker.

Can anyone give me a brief overview of how my workflow should be with docker 1.9 to accomplish this?

Upvotes: 0

Views: 111

Answers (1)

Chris McKinnel
Chris McKinnel

Reputation: 15112

You can do this by having a simple nginx Dockerfile:

FROM ubuntu:14.04

RUN echo "Europe/London" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata 

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y nginx
RUN apt-get install -y supervisor

ADD supervisor.nginx.conf /etc/supervisor.d/nginx.conf
ADD path/to/your/nginx/config /etc/nginx/sites-enabled/default

EXPOSE 80
CMD /usr/bin/supervisord -n

And a simple supervisor.nginx.conf:

[program:nginx]
command=/usr/sbin/nginx
stdout_events_enabled=true
stderr_events_enabled=true

Then building your image:

docker build -t nginx .

Then running your nginx container:

docker run -d -v /path/to/nginx/config:/etc/nginx/sites-enabled/default -p 80:80 nginx

This is assuming that you don't have anything running on port 80 on your host - if you do, you can change 80:80 to something like 8000:80 (in the format hostPort:containerPort.

Using -v and mounting your nginx config from your host is useful to do locally as it allows you to make changes to it without having to go into your container / rebuild it every time, but when you deploy to your server you should run a container that uses a config from inside your image so it's completely repeatable on another machine.

Upvotes: 1

Related Questions