"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[76],{4695:(e,r,o)=>{o.r(r),o.d(r,{assets:()=>c,contentTitle:()=>t,default:()=>d,frontMatter:()=>s,metadata:()=>a,toc:()=>l});var n=o(5893),i=o(1151);const s={title:"Docker Public Share",sidebar_position:10,sidebar_label:"Public Share"},t=void 0,a={id:"guides/docker-share/docker_public_share_guide",title:"Docker Public Share",description:"With zrok and Docker, you can publicly share a web server that's running in a local container or anywhere that's reachable by the zrok container. The share can be reached through a temporary public URL that expires when the container is stopped. If you're looking for a reserved subdomain for the share, check out zrok frontdoor.",source:"@site/../docs/guides/docker-share/docker_public_share_guide.md",sourceDirName:"guides/docker-share",slug:"/guides/docker-share/docker_public_share_guide",permalink:"/docs/guides/docker-share/docker_public_share_guide",draft:!1,unlisted:!1,editUrl:"https://github.com/openziti/zrok/blob/main/docs/../docs/guides/docker-share/docker_public_share_guide.md",tags:[],version:"current",sidebarPosition:10,frontMatter:{title:"Docker Public Share",sidebar_position:10,sidebar_label:"Public Share"},sidebar:"tutorialSidebar",previous:{title:"Docker Share",permalink:"/docs/category/docker-share"},next:{title:"Private Share",permalink:"/docs/guides/docker-share/docker_private_share_guide"}},c={},l=[{value:"Walkthrough Video",id:"walkthrough-video",level:2},{value:"Before You Begin",id:"before-you-begin",level:2},{value:"Begin Sharing with Docker Compose",id:"begin-sharing-with-docker-compose",level:2},{value:"Proxy Any Web Server",id:"proxy-any-web-server",level:2},{value:"Require Authentication",id:"require-authentication",level:2},{value:"Customize Temporary Public Share",id:"customize-temporary-public-share",level:2},{value:"Destroy the zrok Environment",id:"destroy-the-zrok-environment",level:2}];function h(e){const r={a:"a",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",...(0,i.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(r.p,{children:["With zrok and Docker, you can publicly share a web server that's running in a local container or anywhere that's reachable by the zrok container. The share can be reached through a temporary public URL that expires when the container is stopped. If you're looking for a reserved subdomain for the share, check out ",(0,n.jsx)(r.a,{href:"/docs/guides/frontdoor",children:"zrok frontdoor"}),"."]}),"\n",(0,n.jsxs)(r.p,{children:["Here's a short article with an overview of ",(0,n.jsx)(r.a,{href:"/docs/concepts/sharing-public",children:"public sharing with zrok"}),"."]}),"\n",(0,n.jsx)(r.h2,{id:"walkthrough-video",children:"Walkthrough Video"}),"\n",(0,n.jsx)("iframe",{width:"100%",height:"315",src:"https://www.youtube.com/embed/ycov--9ZtB4",title:"YouTube video player",frameborder:"0",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",allowfullscreen:!0}),"\n",(0,n.jsx)(r.h2,{id:"before-you-begin",children:"Before You Begin"}),"\n",(0,n.jsxs)(r.p,{children:["To follow this guide you will need ",(0,n.jsx)(r.a,{href:"https://docs.docker.com/get-docker/",children:"Docker"})," and ",(0,n.jsx)(r.a,{href:"https://docs.docker.com/compose/install/",children:"the Docker Compose plugin"})," for running ",(0,n.jsx)(r.code,{children:"docker compose"})," commands in your terminal."]}),"\n",(0,n.jsx)(r.h2,{id:"begin-sharing-with-docker-compose",children:"Begin Sharing with Docker Compose"}),"\n",(0,n.jsx)(r.p,{children:"A temporary public share is a great way to share a web server running in a container with someone else for a short time."}),"\n",(0,n.jsxs)(r.ol,{children:["\n",(0,n.jsx)(r.li,{children:"Make a folder on your computer to use as a Docker Compose project for your zrok public share."}),"\n",(0,n.jsx)(r.li,{children:"In your terminal, change directory to the newly-created project folder."}),"\n",(0,n.jsxs)(r.li,{children:["Download ",(0,n.jsx)(r.a,{href:"pathname:///zrok-public-share/compose.yml",children:"the temporary public share project file"}),"."]}),"\n",(0,n.jsxs)(r.li,{children:["Copy your zrok environment token from the zrok web console to your clipboard and paste it in a file named ",(0,n.jsx)(r.code,{children:".env"})," in the same folder like this:"]}),"\n"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",metastring:'title=".env"',children:'ZROK_ENABLE_TOKEN="8UL9-48rN0ua"\n'})}),"\n",(0,n.jsxs)(r.ol,{children:["\n",(0,n.jsx)(r.li,{children:"Set the zrok API endpoint if self-hosting zrok. Skip this if using zrok.io."}),"\n"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",metastring:'title=".env"',children:'ZROK_API_ENDPOINT="https://zrok.example.com"\n'})}),"\n",(0,n.jsxs)(r.ol,{children:["\n",(0,n.jsx)(r.li,{children:"Run the Compose project to start sharing the built-in demo web server."}),"\n"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"docker compose up --detach\n"})}),"\n",(0,n.jsxs)(r.ol,{children:["\n",(0,n.jsxs)(r.li,{children:["Get the public share URL from the output of the ",(0,n.jsx)(r.code,{children:"zrok-share"})," service or by peeking in the zrok console where the share will be graphed."]}),"\n"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"docker compose logs zrok-share\n"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-buttonless",metastring:'title="Output"',children:"zrok-public-share-1 | https://w6r1vesearkj.in.zrok.io/\n"})}),"\n",(0,n.jsx)(r.p,{children:"This concludes sharing the demo web server. Read on to learn how to pivot to sharing any web server leveraging additional zrok backend modes."}),"\n",(0,n.jsx)(r.h2,{id:"proxy-any-web-server",children:"Proxy Any Web Server"}),"\n",(0,n.jsxs)(r.p,{children:["The simplest way to share your web server is to set ",(0,n.jsx)(r.code,{children:"ZROK_TARGET"})," (e.g. ",(0,n.jsx)(r.code,{children:"https://example.com"}),") in the environment file."]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",metastring:'title=".env"',children:'ZROK_TARGET="http://example.com:8080"\n'})}),"\n",(0,n.jsx)(r.h2,{id:"require-authentication",children:"Require Authentication"}),"\n",(0,n.jsxs)(r.p,{children:["You can require authentication for your public share by setting ",(0,n.jsx)(r.code,{children:"ZROK_OAUTH_PROVIDER"})," to ",(0,n.jsx)(r.code,{children:"github"})," or ",(0,n.jsx)(r.code,{children:"google"})," with zrok.io. You could parse the authenticated email address from the request cookie if you're building a custom server app. Read more about the OAuth features in ",(0,n.jsx)(r.a,{href:"https://blog.openziti.io/the-zrok-oauth-public-frontend",children:"this blog post"}),"."]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",metastring:'title=".env"',children:'ZROK_OAUTH_PROVIDER="github"\n'})}),"\n",(0,n.jsx)(r.h2,{id:"customize-temporary-public-share",children:"Customize Temporary Public Share"}),"\n",(0,n.jsx)(r.p,{children:"This technique is useful for adding a containerized service to the project, or mounting a filesystem directory into the container to share as a static website or file server."}),"\n",(0,n.jsxs)(r.p,{children:["Any additional services specified in the override file will be merged with ",(0,n.jsx)(r.code,{children:"compose.yml"})," when you ",(0,n.jsx)(r.code,{children:"up"})," the project."]}),"\n",(0,n.jsxs)(r.p,{children:["You may override individual values from in ",(0,n.jsx)(r.code,{children:"compose.yml"})," by specifying them in the override file."]}),"\n",(0,n.jsxs)(r.ol,{children:["\n",(0,n.jsxs)(r.li,{children:["Create a file ",(0,n.jsx)(r.code,{children:"compose.override.yml"}),". This example demonstrates sharing a static HTML directory ",(0,n.jsx)(r.code,{children:"/tmp/html"})," from the Docker host's filesystem."]}),"\n"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-yaml",metastring:'title="compose.override.yml"',children:"services:\n zrok-share:\n command: share public --headless --backend-mode web /tmp/html\n volumes:\n - /tmp/html:/tmp/html\n"})}),"\n",(0,n.jsxs)(r.ol,{children:["\n",(0,n.jsx)(r.li,{children:"Re-run the project to load the new configuration."}),"\n"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"docker compose up --force-recreate --detach\n"})}),"\n",(0,n.jsxs)(r.ol,{children:["\n",(0,n.jsxs)(r.li,{children:["Get the new tempoary public share URL for the ",(0,n.jsx)(r.code,{children:"zrok-share"})," container."]}),"\n"]}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"docker compose logs zrok-share\n"})}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-buttonless",metastring:'title="Output"',children:"zrok-public-share-1 | https://w6r1vesearkj.in.zrok.io/\n"})}),"\n",(0,n.jsx)(r.h2,{id:"destroy-the-zrok-environment",children:"Destroy the zrok Environment"}),"\n",(0,n.jsx)(r.p,{children:"This destroys the Docker volumes containing the zrok environment secrets. The zrok environment can also be destroyed in the web console."}),"\n",(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:"language-bash",children:"docker compose down --volumes\n"})})]})}function d(e={}){const{wrapper:r}={...(0,i.a)(),...e.components};return r?(0,n.jsx)(r,{...e,children:(0,n.jsx)(h,{...e})}):h(e)}},1151:(e,r,o)=>{o.d(r,{Z:()=>a,a:()=>t});var n=o(7294);const i={},s=n.createContext(i);function t(e){const r=n.useContext(s);return n.useMemo((function(){return"function"==typeof e?e(r):{...r,...e}}),[r,e])}function a(e){let r;return r=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:t(e.components),n.createElement(s.Provider,{value:r},e.children)}}}]);