[{"data":1,"prerenderedAt":996},["Reactive",2],{"content-query-TqJmnZdLZJ":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"head":10,"layout":12,"body":13,"_type":991,"_id":992,"_source":993,"_file":994,"_extension":995},"/docs/guide/understanding-file-permissions","guide",false,"","Understanding File Permissions","Eliminate the headache of file permissions when working with PHP + Docker.",{"title":11},"Understanding file permissions - Docker PHP - Server Side Up","docs",{"type":14,"children":15,"toc":984},"root",[16,24,34,43,50,72,85,91,120,126,131,146,151,158,233,239,258,677,682,873,923,928,955,961,966,978],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"understanding-file-permissions",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"lead-p",{},[28],{"type":17,"tag":29,"props":30,"children":31},"p",{},[32],{"type":23,"value":33},"Working with file permissions is one of the biggest headaches when working with PHP + Docker. This generally is because the PHP server also requires a web server to serve static files. By default, this means multiple users are created in the container, and permissions can get out of hand quickly.",{"type":17,"tag":29,"props":35,"children":36},{},[37],{"type":17,"tag":38,"props":39,"children":42},"img",{"alt":40,"src":41},"Traditional PHP File Permissions Configuration","/images/docs/permissions-privileged.png",[],{"type":17,"tag":44,"props":45,"children":47},"h2",{"id":46},"even-more-frustrating-development-environments",[48],{"type":23,"value":49},"Even more frustrating: Development Environments",{"type":17,"tag":29,"props":51,"children":52},{},[53,55,62,64,70],{"type":23,"value":54},"Even if someone configured a single user in the container to run both the PHP server and the web server, things get even more complicated in development environments. For example, if you have Alice running her Windows Machine with WSL2, she might have a user ID of ",{"type":17,"tag":56,"props":57,"children":59},"code",{"className":58},[],[60],{"type":23,"value":61},"1001",{"type":23,"value":63},". Then you have Bob running his Ubuntu workstation with a user ID of ",{"type":17,"tag":56,"props":65,"children":67},{"className":66},[],[68],{"type":23,"value":69},"1002",{"type":23,"value":71},". Meanwhile, Charlie is running his Docker on his macOS machine (that runs a tiny VM) that has a totally different file permission experience compared to Windows and Linux because of the file system differences.",{"type":17,"tag":29,"props":73,"children":74},{},[75,77,83],{"type":23,"value":76},"If a volume is mounted from the container to the host, the container will write files to the host as ",{"type":17,"tag":56,"props":78,"children":80},{"className":79},[],[81],{"type":23,"value":82},"33:33",{"type":23,"value":84},", which will require sudo/root permissions to edit and delete files.",{"type":17,"tag":44,"props":86,"children":88},{"id":87},"our-industry-attempted-workarounds",[89],{"type":23,"value":90},"Our industry attempted workarounds",{"type":17,"tag":29,"props":92,"children":93},{},[94,96,102,104,110,112,118],{"type":23,"value":95},"We've seen experiences that allow users to provide an environment variable of ",{"type":17,"tag":56,"props":97,"children":99},{"className":98},[],[100],{"type":23,"value":101},"PUID",{"type":23,"value":103}," and ",{"type":17,"tag":56,"props":105,"children":107},{"className":106},[],[108],{"type":23,"value":109},"PGID",{"type":23,"value":111},". Although this is a great user experience, it requires the container user to be privileged, which is a major \"no-no\" in the security world. It also had downstream file permission errors if the container failed on initialization where logs would be created by the root user and no longer writable by the ",{"type":17,"tag":56,"props":113,"children":115},{"className":114},[],[116],{"type":23,"value":117},"www-data",{"type":23,"value":119}," user.",{"type":17,"tag":44,"props":121,"children":123},{"id":122},"our-solution",[124],{"type":23,"value":125},"Our solution",{"type":17,"tag":29,"props":127,"children":128},{},[129],{"type":23,"value":130},"We focus on providing the tools to give sysadmins the ability to:",{"type":17,"tag":132,"props":133,"children":134},"ul",{},[135,141],{"type":17,"tag":136,"props":137,"children":138},"li",{},[139],{"type":23,"value":140},"Keep their containers unprivileged by default",{"type":17,"tag":136,"props":142,"children":143},{},[144],{"type":23,"value":145},"Allow the dynamic reconfiguration of the container user and group ID (at build time only)",{"type":17,"tag":29,"props":147,"children":148},{},[149],{"type":23,"value":150},"It's a bummer that we can only set the user and group ID at build time, but it's a small price to pay for the security benefits of running unprivileged containers.",{"type":17,"tag":152,"props":153,"children":155},"h4",{"id":154},"how-it-works",[156],{"type":23,"value":157},"How it works",{"type":17,"tag":132,"props":159,"children":160},{},[161,188,208,221],{"type":17,"tag":136,"props":162,"children":163},{},[164,166,171,173,178,180,186],{"type":23,"value":165},"By default, all our images run ",{"type":17,"tag":56,"props":167,"children":169},{"className":168},[],[170],{"type":23,"value":117},{"type":23,"value":172}," as the user (",{"type":17,"tag":56,"props":174,"children":176},{"className":175},[],[177],{"type":23,"value":82},{"type":23,"value":179}," for Debian and ",{"type":17,"tag":56,"props":181,"children":183},{"className":182},[],[184],{"type":23,"value":185},"82:82",{"type":23,"value":187}," for Alpine)",{"type":17,"tag":136,"props":189,"children":190},{},[191,193,198,200,206],{"type":23,"value":192},"We provide a script that can be called at build time to change the UID and GID of ",{"type":17,"tag":56,"props":194,"children":196},{"className":195},[],[197],{"type":23,"value":117},{"type":23,"value":199}," (called ",{"type":17,"tag":56,"props":201,"children":203},{"className":202},[],[204],{"type":23,"value":205},"docker-php-serversideup-set-id",{"type":23,"value":207},")",{"type":17,"tag":136,"props":209,"children":210},{},[211,213,219],{"type":23,"value":212},"If you need to update permissions of service files (example: NGINX, Apache, Unit, etc), you can run the ",{"type":17,"tag":56,"props":214,"children":216},{"className":215},[],[217],{"type":23,"value":218},"docker-php-serversideup-set-file-permissions",{"type":23,"value":220}," at build",{"type":17,"tag":136,"props":222,"children":223},{},[224,226,231],{"type":23,"value":225},"We will use a multi-stage build to ensure that the ",{"type":17,"tag":56,"props":227,"children":229},{"className":228},[],[230],{"type":23,"value":205},{"type":23,"value":232}," script is not executed in the construction of the final image",{"type":17,"tag":44,"props":234,"children":236},{"id":235},"example",[237],{"type":23,"value":238},"Example",{"type":17,"tag":29,"props":240,"children":241},{},[242,244,249,251,256],{"type":23,"value":243},"Here's an example of ensuring our UID/GID of ",{"type":17,"tag":56,"props":245,"children":247},{"className":246},[],[248],{"type":23,"value":117},{"type":23,"value":250}," will match the development UID/GID of the host machine, while preserving the default UID/GID of ",{"type":17,"tag":56,"props":252,"children":254},{"className":253},[],[255],{"type":23,"value":82},{"type":23,"value":257}," for the final image:",{"type":17,"tag":259,"props":260,"children":262},"code-panel",{"label":261},"Dockerfile",[263],{"type":17,"tag":264,"props":265,"children":269},"pre",{"className":266,"code":267,"language":268,"meta":7,"style":7},"language-dockerfile shiki shiki-themes github-dark github-dark monokai","############################################\n# Base Image\n############################################\nFROM serversideup/php:8.3-fpm-nginx-bookworm AS base\n\n############################################\n# Development Image\n############################################\nFROM base AS development\n\n# Switch to root so we can do root things\nUSER root\n\n# Save the build arguments as a variable\nARG USER_ID\nARG GROUP_ID\n\n# Use the build arguments to change the UID \n# and GID of www-data while also changing \n# the file permissions for NGINX\nRUN docker-php-serversideup-set-id www-data $USER_ID:$GROUP_ID && \\\n    \\\n    # Update the file permissions for our NGINX service to match the new UID/GID\n    docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service nginx\n\n# Drop back to our unprivileged user\nUSER www-data\n\n############################################\n# Production Image\n############################################\n\n# Since we're calling \"base\", production isn't\n# calling any of that permission stuff\nFROM base AS production\n\n# Copy our app files as www-data (33:33)\nCOPY --chown=www-data:www-data . /var/www/html\n","dockerfile",[270],{"type":17,"tag":56,"props":271,"children":272},{"__ignoreMap":7},[273,285,294,302,328,338,346,355,363,385,393,402,416,424,433,447,460,468,477,486,495,509,518,527,536,544,553,566,574,582,591,599,607,616,625,646,654,663],{"type":17,"tag":274,"props":275,"children":278},"span",{"class":276,"line":277},"line",1,[279],{"type":17,"tag":274,"props":280,"children":282},{"style":281},"--shiki-default:#6A737D;--shiki-dark:#6A737D;--shiki-sepia:#88846F",[283],{"type":23,"value":284},"############################################\n",{"type":17,"tag":274,"props":286,"children":288},{"class":276,"line":287},2,[289],{"type":17,"tag":274,"props":290,"children":291},{"style":281},[292],{"type":23,"value":293},"# Base Image\n",{"type":17,"tag":274,"props":295,"children":297},{"class":276,"line":296},3,[298],{"type":17,"tag":274,"props":299,"children":300},{"style":281},[301],{"type":23,"value":284},{"type":17,"tag":274,"props":303,"children":305},{"class":276,"line":304},4,[306,312,318,323],{"type":17,"tag":274,"props":307,"children":309},{"style":308},"--shiki-default:#F97583;--shiki-dark:#F97583;--shiki-sepia:#F92672",[310],{"type":23,"value":311},"FROM",{"type":17,"tag":274,"props":313,"children":315},{"style":314},"--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8;--shiki-sepia:#F8F8F2",[316],{"type":23,"value":317}," serversideup/php:8.3-fpm-nginx-bookworm ",{"type":17,"tag":274,"props":319,"children":320},{"style":308},[321],{"type":23,"value":322},"AS",{"type":17,"tag":274,"props":324,"children":325},{"style":314},[326],{"type":23,"value":327}," base\n",{"type":17,"tag":274,"props":329,"children":331},{"class":276,"line":330},5,[332],{"type":17,"tag":274,"props":333,"children":335},{"emptyLinePlaceholder":334},true,[336],{"type":23,"value":337},"\n",{"type":17,"tag":274,"props":339,"children":341},{"class":276,"line":340},6,[342],{"type":17,"tag":274,"props":343,"children":344},{"style":281},[345],{"type":23,"value":284},{"type":17,"tag":274,"props":347,"children":349},{"class":276,"line":348},7,[350],{"type":17,"tag":274,"props":351,"children":352},{"style":281},[353],{"type":23,"value":354},"# Development Image\n",{"type":17,"tag":274,"props":356,"children":358},{"class":276,"line":357},8,[359],{"type":17,"tag":274,"props":360,"children":361},{"style":281},[362],{"type":23,"value":284},{"type":17,"tag":274,"props":364,"children":366},{"class":276,"line":365},9,[367,371,376,380],{"type":17,"tag":274,"props":368,"children":369},{"style":308},[370],{"type":23,"value":311},{"type":17,"tag":274,"props":372,"children":373},{"style":314},[374],{"type":23,"value":375}," base ",{"type":17,"tag":274,"props":377,"children":378},{"style":308},[379],{"type":23,"value":322},{"type":17,"tag":274,"props":381,"children":382},{"style":314},[383],{"type":23,"value":384}," development\n",{"type":17,"tag":274,"props":386,"children":388},{"class":276,"line":387},10,[389],{"type":17,"tag":274,"props":390,"children":391},{"emptyLinePlaceholder":334},[392],{"type":23,"value":337},{"type":17,"tag":274,"props":394,"children":396},{"class":276,"line":395},11,[397],{"type":17,"tag":274,"props":398,"children":399},{"style":281},[400],{"type":23,"value":401},"# Switch to root so we can do root things\n",{"type":17,"tag":274,"props":403,"children":405},{"class":276,"line":404},12,[406,411],{"type":17,"tag":274,"props":407,"children":408},{"style":308},[409],{"type":23,"value":410},"USER",{"type":17,"tag":274,"props":412,"children":413},{"style":314},[414],{"type":23,"value":415}," root\n",{"type":17,"tag":274,"props":417,"children":419},{"class":276,"line":418},13,[420],{"type":17,"tag":274,"props":421,"children":422},{"emptyLinePlaceholder":334},[423],{"type":23,"value":337},{"type":17,"tag":274,"props":425,"children":427},{"class":276,"line":426},14,[428],{"type":17,"tag":274,"props":429,"children":430},{"style":281},[431],{"type":23,"value":432},"# Save the build arguments as a variable\n",{"type":17,"tag":274,"props":434,"children":436},{"class":276,"line":435},15,[437,442],{"type":17,"tag":274,"props":438,"children":439},{"style":308},[440],{"type":23,"value":441},"ARG",{"type":17,"tag":274,"props":443,"children":444},{"style":314},[445],{"type":23,"value":446}," USER_ID\n",{"type":17,"tag":274,"props":448,"children":450},{"class":276,"line":449},16,[451,455],{"type":17,"tag":274,"props":452,"children":453},{"style":308},[454],{"type":23,"value":441},{"type":17,"tag":274,"props":456,"children":457},{"style":314},[458],{"type":23,"value":459}," GROUP_ID\n",{"type":17,"tag":274,"props":461,"children":463},{"class":276,"line":462},17,[464],{"type":17,"tag":274,"props":465,"children":466},{"emptyLinePlaceholder":334},[467],{"type":23,"value":337},{"type":17,"tag":274,"props":469,"children":471},{"class":276,"line":470},18,[472],{"type":17,"tag":274,"props":473,"children":474},{"style":281},[475],{"type":23,"value":476},"# Use the build arguments to change the UID \n",{"type":17,"tag":274,"props":478,"children":480},{"class":276,"line":479},19,[481],{"type":17,"tag":274,"props":482,"children":483},{"style":281},[484],{"type":23,"value":485},"# and GID of www-data while also changing \n",{"type":17,"tag":274,"props":487,"children":489},{"class":276,"line":488},20,[490],{"type":17,"tag":274,"props":491,"children":492},{"style":281},[493],{"type":23,"value":494},"# the file permissions for NGINX\n",{"type":17,"tag":274,"props":496,"children":498},{"class":276,"line":497},21,[499,504],{"type":17,"tag":274,"props":500,"children":501},{"style":308},[502],{"type":23,"value":503},"RUN",{"type":17,"tag":274,"props":505,"children":506},{"style":314},[507],{"type":23,"value":508}," docker-php-serversideup-set-id www-data $USER_ID:$GROUP_ID && \\\n",{"type":17,"tag":274,"props":510,"children":512},{"class":276,"line":511},22,[513],{"type":17,"tag":274,"props":514,"children":515},{"style":314},[516],{"type":23,"value":517},"    \\\n",{"type":17,"tag":274,"props":519,"children":521},{"class":276,"line":520},23,[522],{"type":17,"tag":274,"props":523,"children":524},{"style":281},[525],{"type":23,"value":526},"    # Update the file permissions for our NGINX service to match the new UID/GID\n",{"type":17,"tag":274,"props":528,"children":530},{"class":276,"line":529},24,[531],{"type":17,"tag":274,"props":532,"children":533},{"style":314},[534],{"type":23,"value":535},"    docker-php-serversideup-set-file-permissions --owner $USER_ID:$GROUP_ID --service nginx\n",{"type":17,"tag":274,"props":537,"children":539},{"class":276,"line":538},25,[540],{"type":17,"tag":274,"props":541,"children":542},{"emptyLinePlaceholder":334},[543],{"type":23,"value":337},{"type":17,"tag":274,"props":545,"children":547},{"class":276,"line":546},26,[548],{"type":17,"tag":274,"props":549,"children":550},{"style":281},[551],{"type":23,"value":552},"# Drop back to our unprivileged user\n",{"type":17,"tag":274,"props":554,"children":556},{"class":276,"line":555},27,[557,561],{"type":17,"tag":274,"props":558,"children":559},{"style":308},[560],{"type":23,"value":410},{"type":17,"tag":274,"props":562,"children":563},{"style":314},[564],{"type":23,"value":565}," www-data\n",{"type":17,"tag":274,"props":567,"children":569},{"class":276,"line":568},28,[570],{"type":17,"tag":274,"props":571,"children":572},{"emptyLinePlaceholder":334},[573],{"type":23,"value":337},{"type":17,"tag":274,"props":575,"children":577},{"class":276,"line":576},29,[578],{"type":17,"tag":274,"props":579,"children":580},{"style":281},[581],{"type":23,"value":284},{"type":17,"tag":274,"props":583,"children":585},{"class":276,"line":584},30,[586],{"type":17,"tag":274,"props":587,"children":588},{"style":281},[589],{"type":23,"value":590},"# Production Image\n",{"type":17,"tag":274,"props":592,"children":594},{"class":276,"line":593},31,[595],{"type":17,"tag":274,"props":596,"children":597},{"style":281},[598],{"type":23,"value":284},{"type":17,"tag":274,"props":600,"children":602},{"class":276,"line":601},32,[603],{"type":17,"tag":274,"props":604,"children":605},{"emptyLinePlaceholder":334},[606],{"type":23,"value":337},{"type":17,"tag":274,"props":608,"children":610},{"class":276,"line":609},33,[611],{"type":17,"tag":274,"props":612,"children":613},{"style":281},[614],{"type":23,"value":615},"# Since we're calling \"base\", production isn't\n",{"type":17,"tag":274,"props":617,"children":619},{"class":276,"line":618},34,[620],{"type":17,"tag":274,"props":621,"children":622},{"style":281},[623],{"type":23,"value":624},"# calling any of that permission stuff\n",{"type":17,"tag":274,"props":626,"children":628},{"class":276,"line":627},35,[629,633,637,641],{"type":17,"tag":274,"props":630,"children":631},{"style":308},[632],{"type":23,"value":311},{"type":17,"tag":274,"props":634,"children":635},{"style":314},[636],{"type":23,"value":375},{"type":17,"tag":274,"props":638,"children":639},{"style":308},[640],{"type":23,"value":322},{"type":17,"tag":274,"props":642,"children":643},{"style":314},[644],{"type":23,"value":645}," production\n",{"type":17,"tag":274,"props":647,"children":649},{"class":276,"line":648},36,[650],{"type":17,"tag":274,"props":651,"children":652},{"emptyLinePlaceholder":334},[653],{"type":23,"value":337},{"type":17,"tag":274,"props":655,"children":657},{"class":276,"line":656},37,[658],{"type":17,"tag":274,"props":659,"children":660},{"style":281},[661],{"type":23,"value":662},"# Copy our app files as www-data (33:33)\n",{"type":17,"tag":274,"props":664,"children":666},{"class":276,"line":665},38,[667,672],{"type":17,"tag":274,"props":668,"children":669},{"style":308},[670],{"type":23,"value":671},"COPY",{"type":17,"tag":274,"props":673,"children":674},{"style":314},[675],{"type":23,"value":676}," --chown=www-data:www-data . /var/www/html\n",{"type":17,"tag":29,"props":678,"children":679},{},[680],{"type":23,"value":681},"To show a simple Docker Compose file example for development, we could use:",{"type":17,"tag":259,"props":683,"children":685},{"label":684},"docker-compose.yml",[686],{"type":17,"tag":264,"props":687,"children":691},{"className":688,"code":689,"language":690,"meta":7,"style":7},"language-yaml shiki shiki-themes github-dark github-dark monokai","services:\n  php:\n    build:\n      context: .\n      target: development\n      args:\n        # UID and GID must be set as environment variables on the host machine\n        USER_ID: $UID\n        GROUP_ID: $GID\n    ports:\n      - 80:8080\n    volumes:\n      - .:/var/www/html\n","yaml",[692],{"type":17,"tag":56,"props":693,"children":694},{"__ignoreMap":7},[695,709,721,733,752,770,782,790,807,824,836,849,861],{"type":17,"tag":274,"props":696,"children":697},{"class":276,"line":277},[698,704],{"type":17,"tag":274,"props":699,"children":701},{"style":700},"--shiki-default:#85E89D;--shiki-dark:#85E89D;--shiki-sepia:#F92672",[702],{"type":23,"value":703},"services",{"type":17,"tag":274,"props":705,"children":706},{"style":314},[707],{"type":23,"value":708},":\n",{"type":17,"tag":274,"props":710,"children":711},{"class":276,"line":287},[712,717],{"type":17,"tag":274,"props":713,"children":714},{"style":700},[715],{"type":23,"value":716},"  php",{"type":17,"tag":274,"props":718,"children":719},{"style":314},[720],{"type":23,"value":708},{"type":17,"tag":274,"props":722,"children":723},{"class":276,"line":296},[724,729],{"type":17,"tag":274,"props":725,"children":726},{"style":700},[727],{"type":23,"value":728},"    build",{"type":17,"tag":274,"props":730,"children":731},{"style":314},[732],{"type":23,"value":708},{"type":17,"tag":274,"props":734,"children":735},{"class":276,"line":304},[736,741,746],{"type":17,"tag":274,"props":737,"children":738},{"style":700},[739],{"type":23,"value":740},"      context",{"type":17,"tag":274,"props":742,"children":743},{"style":314},[744],{"type":23,"value":745},": ",{"type":17,"tag":274,"props":747,"children":749},{"style":748},"--shiki-default:#79B8FF;--shiki-dark:#79B8FF;--shiki-sepia:#AE81FF",[750],{"type":23,"value":751},".\n",{"type":17,"tag":274,"props":753,"children":754},{"class":276,"line":330},[755,760,764],{"type":17,"tag":274,"props":756,"children":757},{"style":700},[758],{"type":23,"value":759},"      target",{"type":17,"tag":274,"props":761,"children":762},{"style":314},[763],{"type":23,"value":745},{"type":17,"tag":274,"props":765,"children":767},{"style":766},"--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF;--shiki-sepia:#E6DB74",[768],{"type":23,"value":769},"development\n",{"type":17,"tag":274,"props":771,"children":772},{"class":276,"line":340},[773,778],{"type":17,"tag":274,"props":774,"children":775},{"style":700},[776],{"type":23,"value":777},"      args",{"type":17,"tag":274,"props":779,"children":780},{"style":314},[781],{"type":23,"value":708},{"type":17,"tag":274,"props":783,"children":784},{"class":276,"line":348},[785],{"type":17,"tag":274,"props":786,"children":787},{"style":281},[788],{"type":23,"value":789},"        # UID and GID must be set as environment variables on the host machine\n",{"type":17,"tag":274,"props":791,"children":792},{"class":276,"line":357},[793,798,802],{"type":17,"tag":274,"props":794,"children":795},{"style":700},[796],{"type":23,"value":797},"        USER_ID",{"type":17,"tag":274,"props":799,"children":800},{"style":314},[801],{"type":23,"value":745},{"type":17,"tag":274,"props":803,"children":804},{"style":766},[805],{"type":23,"value":806},"$UID\n",{"type":17,"tag":274,"props":808,"children":809},{"class":276,"line":365},[810,815,819],{"type":17,"tag":274,"props":811,"children":812},{"style":700},[813],{"type":23,"value":814},"        GROUP_ID",{"type":17,"tag":274,"props":816,"children":817},{"style":314},[818],{"type":23,"value":745},{"type":17,"tag":274,"props":820,"children":821},{"style":766},[822],{"type":23,"value":823},"$GID\n",{"type":17,"tag":274,"props":825,"children":826},{"class":276,"line":387},[827,832],{"type":17,"tag":274,"props":828,"children":829},{"style":700},[830],{"type":23,"value":831},"    ports",{"type":17,"tag":274,"props":833,"children":834},{"style":314},[835],{"type":23,"value":708},{"type":17,"tag":274,"props":837,"children":838},{"class":276,"line":395},[839,844],{"type":17,"tag":274,"props":840,"children":841},{"style":314},[842],{"type":23,"value":843},"      - ",{"type":17,"tag":274,"props":845,"children":846},{"style":766},[847],{"type":23,"value":848},"80:8080\n",{"type":17,"tag":274,"props":850,"children":851},{"class":276,"line":404},[852,857],{"type":17,"tag":274,"props":853,"children":854},{"style":700},[855],{"type":23,"value":856},"    volumes",{"type":17,"tag":274,"props":858,"children":859},{"style":314},[860],{"type":23,"value":708},{"type":17,"tag":274,"props":862,"children":863},{"class":276,"line":418},[864,868],{"type":17,"tag":274,"props":865,"children":866},{"style":314},[867],{"type":23,"value":843},{"type":17,"tag":274,"props":869,"children":870},{"style":766},[871],{"type":23,"value":872},".:/var/www/html\n",{"type":17,"tag":29,"props":874,"children":875},{},[876,878,884,886,892,894,899,901,906,908,914,915,921],{"type":23,"value":877},"When we run ",{"type":17,"tag":56,"props":879,"children":881},{"className":880},[],[882],{"type":23,"value":883},"docker compose up",{"type":23,"value":885},", our compose file directs us to build the ",{"type":17,"tag":56,"props":887,"children":889},{"className":888},[],[890],{"type":23,"value":891},"development",{"type":23,"value":893}," target. This target will run the ",{"type":17,"tag":56,"props":895,"children":897},{"className":896},[],[898],{"type":23,"value":205},{"type":23,"value":900}," script to change the UID and GID of ",{"type":17,"tag":56,"props":902,"children":904},{"className":903},[],[905],{"type":23,"value":117},{"type":23,"value":907}," to match the host machine (assuming ",{"type":17,"tag":56,"props":909,"children":911},{"className":910},[],[912],{"type":23,"value":913},"$UID",{"type":23,"value":103},{"type":17,"tag":56,"props":916,"children":918},{"className":917},[],[919],{"type":23,"value":920},"$GID",{"type":23,"value":922}," are set in a zsh/bash profile or something similar). This will allow us to run the container as an unprivileged user while still having the correct permissions to read and write files.",{"type":17,"tag":29,"props":924,"children":925},{},[926],{"type":23,"value":927},"The best thing is the user can delete files off of their machine without being prompted for sudo permissions. This is because we're aligning the UID/GID of the container with the host machine.",{"type":17,"tag":29,"props":929,"children":930},{},[931,933,939,941,946,948,953],{"type":23,"value":932},"When it comes to building our image for production, we just use the ",{"type":17,"tag":56,"props":934,"children":936},{"className":935},[],[937],{"type":23,"value":938},"production",{"type":23,"value":940}," target, which will copy the files as ",{"type":17,"tag":56,"props":942,"children":944},{"className":943},[],[945],{"type":23,"value":117},{"type":23,"value":947}," with the default UID/GID of ",{"type":17,"tag":56,"props":949,"children":951},{"className":950},[],[952],{"type":23,"value":82},{"type":23,"value":954},".",{"type":17,"tag":44,"props":956,"children":958},{"id":957},"an-optimized-experience-from-development-to-production",[959],{"type":23,"value":960},"An optimized experience from development to production",{"type":17,"tag":29,"props":962,"children":963},{},[964],{"type":23,"value":965},"If you like the concepts above and you're looking for an optimized experience for developers (especially when it comes simplifying the setting of UID/GID), we recommend checking out our other open source project Spin. Spin is a lightweight wrapper for Docker Compose that allows you to manage your environment from development to production.",{"type":17,"tag":29,"props":967,"children":968},{},[969],{"type":17,"tag":970,"props":971,"children":975},"a",{"href":972,"rel":973},"https://serversideup.net/open-source/spin/",[974],"nofollow",[976],{"type":23,"value":977},"Learn more about Spin →",{"type":17,"tag":979,"props":980,"children":981},"style",{},[982],{"type":23,"value":983},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html .sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}html.sepia .shiki span {color: var(--shiki-sepia);background: var(--shiki-sepia-bg);font-style: var(--shiki-sepia-font-style);font-weight: var(--shiki-sepia-font-weight);text-decoration: var(--shiki-sepia-text-decoration);}",{"title":7,"searchDepth":287,"depth":287,"links":985},[986,987,988,989,990],{"id":46,"depth":287,"text":49},{"id":87,"depth":287,"text":90},{"id":122,"depth":287,"text":125},{"id":235,"depth":287,"text":238},{"id":957,"depth":287,"text":960},"markdown","content:docs:3.guide:2.understanding-file-permissions.md","content","docs/3.guide/2.understanding-file-permissions.md","md",1727889428224]