How to build Docker Image for NGINX using Chef (chef-solo)?

package [‘nginx’] do action :install end

package [‘php7.0-fpm’] do action :install end

package [‘php-imagick’, ‘php-curl’, ‘php-gd’, ‘php-mcrypt’, ‘php-xml’, ‘php-mbstring’, ‘php-soap’, ‘php-mysql’, ‘php-pear’] do action :install end

package [‘ntp’, ‘htop’, ‘vim’] do action :install end

template ‘/etc/nginx/sites-enabled/default’ do source ‘default.conf’ end

Default server configuration

server { listen 80 default_server; listen [::]:80 default_server;

# SSL configuration
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
# Note: You should disable gzip for SSL traffic.
# See:
# Read up on ssl_ciphers to ensure a secure configuration.
# See:
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
# include snippets/snakeoil.conf;

root /app;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;

# pass the PHP scripts to FastCGI server listening on
location ~ \.php$ {
    include snippets/fastcgi-php.conf;

    # With php7.0-cgi alone:
#   fastcgi_pass;
    # With php7.0-fpm:
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#location ~ /\.ht {
#   deny all;


Virtual Host configuration for

You can move that to a different file under sites-available/ and symlink that

to sites-enabled/ to enable it.

#server {

listen 80;

listen [::]:80;


root /var/www/;

index index.html;

location / {

try_files $uri $uri/ =404;



RUN apt-get -y update RUN apt-get -y install python-software-properties RUN apt-get -y update

ADD ./Berksfile /Berksfile ADD ./solo.rb /var/chef/solo.rb ADD ./solo.json /var/chef/solo.json ADD ./cookbooks /var/chef/cookbooks

RUN cd / && /opt/chef/embedded/bin/berks vendor /var/chef/cookbooks RUN chef-solo -c /var/chef/solo.rb -j /var/chef/solo.json

CMD service php7.0-fpm start && nginx -g “daemon off;”

docker run -d -p 8080:80 majdarbash/nginx bash (overriding CMD entry point, to access bash, e.g. troubleshopt)

running with mounted volume in www (note that nginx will serve from /app based on the chef template above)

docker run -v ~/Developer/docker-chef-solo-skeleton/www:/app -p 8080:80 -d majdarbash/nginx

pushing the image to the repository

docker push majdarbash/nginx

docker run -v [local_directory]:/app -p 8080:80 -d majdarbash/nginx