Skip to content

Latest commit

 

History

History
121 lines (88 loc) · 2.71 KB

File metadata and controls

121 lines (88 loc) · 2.71 KB

Dummy Puma Sinatra Docker app. running on a socket

Open Thanks Gittens

Docker image

Given your NginX server is expecting connection on unix socket unix:///var/shared/app.sock This docker image recipe will run small Sinatra dummy application that will run Puma server on this socket.

For example:

/etc/nginx/nginx.conf
# ...
upstream myapp {
  server unix:///var/shared/app.sock;
}
# ...

Step 1 - Run Puma

option 1 - Run as Docker Image

docker pull equivalent/dummy-sinatra-puma-socket-docker-app

# Run Docker image
mkdir -p /tmp/dummy-app
docker run -v /tmp/dummy-app/:/var/shared/ -d equivalent/dummy-sinatra-puma-socket-docker-app

# Check
docker ps

Now you have a Puma running on a socket /tmp/dummy-app/app.sock

option 2 - Build Docker image locally and run Docker image

git clone [email protected]:equivalent/dummy-sinatra-puma-socket-docker-app.git
cd ./dummy-sinatra-puma-socket-docker-app

# build docker image
docker build -t=dummy-sinatra-puma-socket-docker-app .

# Prepare and run Docker image
mkdir -p /tmp/dummy-app
docker run -v /tmp/dummy-app/:/var/shared/ -d dummy-sinatra-puma-socket-docker-app

# Check
docker ps

option 3 - Running as Ruby without Docker

To launch server

git clone [email protected]:equivalent/dummy-sinatra-puma-socket-docker-app.git
cd ./dummy-sinatra-puma-socket-docker-app
bundle install
bundle exec puma config.ru -C puma.rb

Now you have a puma running on a socket /tmp/dummy-app/app.sock

step 2 - Launch NginX

Create & start NginX that is expecting connection on socket /tmp/dummy-app/app.sock

for example:

/etc/nginx/nginx.conf
# ...
upstream myapp {
  server unix:///tmp/dummy-app/app.sock;
}
# ...

or build a Docker NginX image using your config

/etc/nginx/nginx.conf
# ...
upstream myapp {
  server unix:///var/shared/app.sock;
}

# ...

server {
  # ...
  location / {
    # ...
    proxy_pass        http://myapp;
    # ...
  }
}
cd ./your-nginx-docker-project
docker build -t=testnginx .
docker run -v /tmp/dummy-app/:/var/shared/ -p 80:80 -it testnginx

if you are getting 504 you may be running nginx before Puma server

Notes