投稿時間:2022-06-27 17:38:19 RSSフィード2022-06-27 17:00 分まとめ(39件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT ITmedia 総合記事一覧 [ITmedia News] 電力需給ひっ迫注意報、28日も継続 https://www.itmedia.co.jp/news/articles/2206/27/news164.html itmedia 2022-06-27 16:40:00
IT ITmedia 総合記事一覧 [ITmedia PC USER] グラフィックスカードを内蔵できる小型ベアボーン「Desk Meet」がデビュー https://www.itmedia.co.jp/pcuser/articles/2206/27/news157.html keychronk 2022-06-27 16:30:00
IT ITmedia 総合記事一覧 [ITmedia ビジネスオンライン] USJ、小学生以下の宿泊料金を実質無料に JR西日本と特別プラン発売 https://www.itmedia.co.jp/business/articles/2206/27/news155.html itmedia 2022-06-27 16:15:00
IT 情報システムリーダーのためのIT情報専門サイト IT Leaders インテック、ログ管理「LogRevi」に「働き方可視化ダッシュボード」、サービス残業などを検出 | IT Leaders https://it.impress.co.jp/articles/-/23379 インテック、ログ管理「LogRevi」に「働き方可視化ダッシュボード」、サービス残業などを検出ITLeadersインテックは年月日、ログ管理ソフトウェア「LogRevi」のオプション機能「働き方可視化ダッシュボード」を発表した。 2022-06-27 16:44:00
AWS AWS Japan Blog Qiskit provider for Amazon Braket のご紹介 https://aws.amazon.com/jp/blogs/news/introducing-the-qiskit-provider-for-amazon-braket/ itproviderforamazonbraket 2022-06-27 07:43:39
Google Google Japan Blog ユーザー体験の向上とモバイルエコシステムの成長を維持するために http://japan.googleblog.com/feeds/4200369753058817344/comments/default ユーザー体験の向上とモバイルエコシステムの成長を維持するためにモバイルエコシステムの運営方法、そして、プラットフォームが開発者やユーザーに十分な選択肢と柔軟性を提供するために優れた政策が果たす役割について、世界的に多くの議論がされてきました。 2022-06-27 16:21:00
js JavaScriptタグが付けられた新着投稿 - Qiita プログラミング初心者に役立ちそうなサイト https://qiita.com/2022tatsuyakitahara/items/a9b1ab8cd5db427ceb19 長野県 2022-06-27 16:05:17
Linux Ubuntuタグが付けられた新着投稿 - Qiita Ubuntu20.04にVMWare Playerをインストールする https://qiita.com/kannkyo/items/b1cf86925ef5a6e30dfa tetcosreleasenameubuntuv 2022-06-27 16:55:01
Docker dockerタグが付けられた新着投稿 - Qiita ローカル開発に便利なShellScript https://qiita.com/aoma/items/83022751dd1d1fb7e47a composerinstall 2022-06-27 16:07:25
Azure Azureタグが付けられた新着投稿 - Qiita 窓辺クラウディアの思い出 https://qiita.com/shobota/items/53b5da20d8569249d9f8 azure 2022-06-27 16:49:39
Azure Azureタグが付けられた新着投稿 - Qiita 【抄訳】.NET MAUI の使用を開始するための新しいリソース https://qiita.com/Azure_App_Innovation_team/items/2133fea31b7da7a56e32 newreso 2022-06-27 16:15:50
Azure Azureタグが付けられた新着投稿 - Qiita Azure Virtual Network Managerによるハブアンドスポーク構成と一部のスポーク間の直接接続 https://qiita.com/zukakosan/items/46471b924e687dfbbdd0 azure 2022-06-27 16:09:06
Git Gitタグが付けられた新着投稿 - Qiita 【GitHub】草の偽造方法 https://qiita.com/SNQ-2001/items/c7b530012a86c0c80859 github 2022-06-27 16:43:16
Git Gitタグが付けられた新着投稿 - Qiita 自作コマンドで業務効率UP https://qiita.com/aoma/items/acc20e7247525808ded5 開発 2022-06-27 16:07:13
技術ブログ Developers.IO 【小ネタ】Amazon QuickSight でデータのタイムゾーンを変換する https://dev.classmethod.jp/articles/change-timezone-on-quicksight/ amazonquicksight 2022-06-27 07:52:18
技術ブログ Developers.IO Alteryx を使って JSON ファイルを CSV や Excel などの表形式に変換する方法 https://dev.classmethod.jp/articles/json-to-csv-excel-alteryx-jp/ alteryx 2022-06-27 07:31:25
技術ブログ Developers.IO Converting JSON file to CSV or Excel using Alteryx https://dev.classmethod.jp/articles/json-to-csv-excel-alteryx-en/ elationshipofajsonfileit 2022-06-27 07:30:49
海外TECH DEV Community How to build a Docker development setup for PHP Projects [Tutorial Part 1] https://dev.to/pascallandau/how-to-build-a-docker-development-setup-for-php-projects-tutorial-part-1-10km How to build a Docker development setup for PHP Projects Tutorial Part This article appeared first on at How to build a Docker development setup for PHP Projects Tutorial Part Caution There is a follow up version of this article available that was published in please make sure to read that as well Docker from scratch for PHP Applications in In this part of my tutorial series on developing PHP on Docker we ll lay the fundamentals to build a complete development infrastructure and explain how to structure the Docker setup as part of a PHP project Structure as in folder structure what to put where Dockerfile templatessolving common problems file permissions runtime configuration We will also create a minimal container setup consisting of php fpm nginx and a workspace container that we refactor from the previous parts of this tutorial All code samples are publicly available in my Docker PHP Tutorial repository on Github The branch for this tutorial is part structuring the docker setup for php projects All published parts of the Docker PHP Tutorial are collected under a dedicated page at Docker PHP Tutorial The previous part was Setting up PhpStorm with Xdebug for local development on Docker and the following one is Docker from scratch for PHP Applications in If you want to follow along please subscribe to the RSS feed or via email to get automatic notifications when the next part comes out Table of contentsIntroductionStructuring the repositoryThe docker folderThe shared folderdocker test sh env example and docker compose ymlThe MakefileDefining services php fpm nginx and workspacephp fpmModifying the pool configurationCustom ENTRYPOINTnginxworkspace formerly php cli Setting up docker compose docker compose yml env exampleBuilding and running the containersTesting if everything worksMakefile and bashrcUsing make as central entry pointInstall make on Windows MinGW Easy container access via din bashrc helperFundamentals on building the containersUnderstanding build contextDockerfile templateSetting the timezoneSynchronizing file and folder ownership on shared volumesModifying configuration filesProviding additional config filesChanging non static valuesInstalling php extensionsInstalling common softwareCleaning upUsing ENTRYPOINT for pre run configurationProviding host docker internal for linux host systemsWrapping up IntroductionWhen I started my current role as Head of Marketing Technology at ABOUT YOU back in we heavily relied on Vagrant namely Homestead as our development infrastructure Though that was much better than working on our local machines we ve run into a couple of problems along the way e g diverging software bloated images slow starting times complicated readme for onboarding upgrading php Today everything that we need for the infrastructure is under source control and committed in the same repository that we use for our main application In effect we get the same infrastructure for every developer including automatic updates for free It is extremely easy to tinker around with updates new tools due to the ephemeral nature of docker as tear down and rebuild only take one command and a couple of minutes To get a feeling for how the process feels like simply execute the following commands git clone cd docker php tutorialgit checkout part structuring the docker setup for php projectsmake docker cleanmake docker initmake docker build from scratchmake docker testYou should now have a running docker environment to develop PHP on docker unless something is blocking your port or you don t have make installed Structuring the repositoryWhile playing around with docker I ve tried different ways to structure files and folders and ended up with the following concepts everything related to docker is placed in a docker directory on on the same level as the main applicationin this directoryeach service gets its own subdirectory for configurationis a shared folder containing scripts and configuration required by multiple servicesis an env example file containing variables for the docker compose ymlis a docker test sh file containing high level tests to validate the docker containersa Makefile with common instructions to control Docker is placed in the repository rootThe result looks roughly like this lt project gt ├ー docker ├ー shared ├ーconfig └ーscripts ├ーphp fpm └ーDockerfile ├ー lt additional services gt ├ー env example ├ーdocker compose yml └ーdocker test sh├ーMakefile├ーindex php└ー lt additional app files gt The docker folderAs I mentioned for me it makes a lot of sense to keep the infrastructure definition close to the codebase because it is immediately available to every developer For bigger projects with multiple components there will be a code infrastructure coupling anyways e g in my experience it is usually not possible to simply switch MySQL for PostgreSQL without any other changes and for a library it is a very convenient although opinionated way to get started I personally find it rather frustrating when I want to contribute to an open source project but find myself spending a significant amount of time setting the environment up correctly instead of being able to just work on the code Ymmv though e g because you don t want everybody with write access to your app repo also to be able to change your infrastructure code We actually went a different route previously and had a second repository inf that would contain the contents of the docker folder lt project inf gt ├ー shared ├ーconfig └ーscripts ├ーphp fpm └ーDockerfile├ー lt additional services gt ├ー env example└ーdocker compose yml lt project gt ├ーindex php└ー lt additional app files gt Worked as well but we often ran into situations where the contents of the repo would be stale for some devs plus it was simply additional overhead with not other benefits to us at that point Maybe git submodules will enable us to get the best of both worlds I ll blog about it once we try The shared folderWhen dealing with multiple services chances are high that some of those services will be configured similarly e g forinstalling common software setting up unix users with the same ids configuration think php cli for workers and php fpm for web requests To avoid duplication I place scripts simple bash files and config files in the shared folder and make it available in the build context for each service I ll explain the process in more detail under providing the correct build context docker test shIs really just a simple bash script that includes some high level tests to make sure that the containers are built correctly See section Testing if everything works env example and docker compose ymldocker compose uses a env file for a convenient way to define and substitute environment variables Since this env file is environment specific it is NOTpart of the repository i e ignored via gitignore Instead we provide a env example file that contains the required environment variables including reasonable default values A new dev would usually run cp env example env after checking out the repository for the first time See section env example The Makefile make and Makefilesare among those things that I ve heard about occasionally but never really cared to understand mostly because I associated them with C Boy did I miss out I was comparing different strategies to provide code quality tooling style checkers static analyzers tests and went from custom bash scripts over composer scripts to finally end up at Makefiles The Makefile serves as a central entry point and simplifies the management of the docker containers e g for re building starting stopping logging in etc See section Makefile and bashrc Defining services php fpm nginx and workspaceLet s have a look at a real example and refactor the php cli php fpm and nginx containers from the first part of this tutorial series This is the folder structure lt project gt ├ー docker ├ー shared ├ーconfig └ーphp └ーconf d └ーzz app ini └ーscripts └ーdocker entrypoint └ーresolve docker host ip sh ├ーnginx ├ーsites available └ーdefault conf ├ーDockerfile └ーnginx conf ├ーphp fpm ├ーphp fpm d └ーpool conf └ーDockerfile ├ーworkspace formerly php cli ├ー ssh └ーinsecure id rsa └ーinsecure id rsa pub └ーDockerfile ├ー env example ├ーdocker compose yml └ーdocker test sh├ーMakefile└ーindex php php fpmClick here to see the full php fpm Dockerfile Since we will be having two PHP containers we need to place the common ini settings in the shared directory ├ー shared ├ーconfig └ーphp └ーconf d └ーzz app iniFor now zz app ini will only contain our opcache setup enable opcacheopcache enable cli opcache enable opcache fast shutdown revalidate everytime effectively disabled for development opcache validate timestamps The pool configuration is only relevant for php fpm so it goes in the directory of the service Btw I highly recommend this video on PHP FPM Configuration if your php fpm foo isn t already over ├ーphp fpm ├ーphp fpm d └ーpool conf Modifying the pool configurationWe re using the modify config sh script to set the user and group that owns the php fpm processes php fpm pool configCOPY SERVICE DIR php fpm d usr local etc php fpm dRUN tmp scripts modify config sh usr local etc php fpm d zz default conf APP USER APP USER amp amp tmp scripts modify config sh usr local etc php fpm d zz default conf APP GROUP APP GROUP Custom ENTRYPOINTSince php fpm needs to be debuggable we need to ensure that the host docker internal DNS entry exists so we ll use the corresponding ENTRYPOINT to do that entrypointRUN mkdir p bin docker entrypoint amp amp cp tmp scripts docker entrypoint bin docker entrypoint amp amp chmod x R bin docker entrypoint ENTRYPOINT bin docker entrypoint resolve docker host ip sh php fpm nginxClick here to see the full nginx Dockerfile The nginx setup is even simpler There is no shared config so that everything we need resides in ├ーnginx ├ーsites available └ーdefault conf ├ーDockerfile └ーnginx confPlease note that nginx only has the nginx conf file for configuration i e there is no conf d directory or so so we need to define the full config in there user APP USER APP GROUP worker processes pid run nginx pid daemon off http include etc nginx sites available conf There are two things to note user and group are modified dynamicallywe specify etc nginx sites available as the directory that holds the config files for the individual files viainclude etc nginx sites available conf We need to keep the last point in mind because we must use the same directory in the Dockerfile nginx app configCOPY SERVICE DIR sites available etc nginx sites available The site s config file default conf has a variable NGINX ROOT for the root directive and we connect it with the fpm container via fastcgi pass php fpm server root NGINX ROOT location php fastcgi pass php fpm php fpm will resolve to the php fpm container because we use php fpm as the service name in the docker compose file so it will be automatically used as the hostname Other containers on the same network can use either the service name or an alias to connect to one of the service s containers In the Dockerfile we useARG APP CODE PATHRUN tmp scripts modify config sh etc nginx sites available default conf NGINX ROOT APP CODE PATH APP CODE PATH will be passed via docker compose when we build the container and mounted as a shared directory from the host system workspace formerly php cli Click here to see the full workspace Dockerfile We will use the former php cli container and make it our workspace as introduced in part of this tutorial under Preparing the workspace container This will be the container we use to point our IDE to e g to execute tests Its Dockerfile looks almost identical to the one of the php fpm service apart from the SSH setup set up sshRUN apt get update yqq amp amp apt get install yqq openssh server amp amp mkdir var run sshd add default public key to authorized keysUSER APP USER COPY SERVICE DIR ssh insecure id rsa pub tmp insecure id rsa pubRUN mkdir p ssh amp amp cat tmp insecure id rsa pub gt gt ssh authorized keys amp amp chown R APP USER ssh amp amp chmod ssh amp amp chmod ssh authorized keys USER root Setting up docker composeIn order to orchestrate the build process we ll use docker compose docker compose ymlSee the full docker compose yml file in the repositoryThings to note each service uses context so it has access to the shared folder The context is always relative to the location of the first docker compose yml fileall arguments that we used in the Dockerfiles are defined in the args section via args APP CODE PATH APP CODE PATH CONTAINER APP GROUP APP GROUP APP GROUP ID APP GROUP ID APP USER APP USER APP USER ID APP USER ID TZ TIMEZONE the codebase is synced from the host in all containers via volumes APP CODE PATH HOST APP CODE PATH CONTAINER the nginx service exposes ports on the host machine so that we can access the containers from outside via ports NGINX HOST HTTP PORT NGINX HOST HTTPS PORT all services are part of the backend network so they can talk to eachother The nginx service has an additional alias that allows us todefine an arbitrary host name via networks backend aliases APP HOST I prefer to have a dedicated hostname per project e g docker php tutorial local instead of using or localhost directly env exampleTo fill in all the required variables arguments we re using a env example file with the following content Default settings for docker composeCOMPOSE PROJECT NAME docker php tutorialCOMPOSE FILE docker compose ymlCOMPOSE CONVERT WINDOWS PATHS buildPHP VERSION TIMEZONE UTCNETWORKS DRIVER bridge applicationAPP USER www dataAPP GROUP www dataAPP USER ID APP GROUP ID APP CODE PATH HOST APP CODE PATH CONTAINER var www current required so we can reach the nginx server from other containers via that hostnameAPP HOST docker php tutorial local nginxNGINX HOST HTTP PORT NGINX HOST HTTPS PORT workspaceWORKSPACE HOST SSH PORT The COMPOSE variables in the beginning set some reasonable defaults for docker compose Building and running the containers By now we should have everything we need set up to get our dockerized PHP development up and running If you haven t done it already now would be a great time to clone the repository and checkout the part structuring the docker setup for php projects branch git clone cd docker php tutorialgit checkout part structuring the docker setup for php projectsNow copy the env exmaple to env All the default values should work out of the box unless you already have something running on port or In that case you have to change NGINX HOST HTTP PORT NGINX HOST HTTP PORT to a free port cp env example envWe can examine the final docker compose yml after the variable substitution viadocker compose f docker docker compose yml project directory docker confignetworks backend driver bridgeservices nginx build args APP CODE PATH var www current APP GROUP www data APP GROUP ID APP USER www data APP USER ID TZ UTC context D codebase docker php tutorial docker dockerfile nginx Dockerfile image php docker tutorial nginx networks backend aliases docker php tutorial local ports published target published target volumes d codebase docker php tutorial var www current rw php fpm Note that this command is run from docker php tutorial If we would run this from docker php tutorial docker we could simply use docker compose config but since we ll define that in a Makefile later anyway the additional verbosity won t matter This command is also a great way to check the various paths that are resolved to their absolute form e g context D codebase docker php tutorial docker andvolumes d codebase docker php tutorial var www current rwThe actual build is triggered viadocker compose f docker docker compose yml project directory docker build parallel Since we have more than one container it makes sense to build with parallel To start the containers we usedocker compose f docker docker compose yml project directory docker up d and should see docker compose f docker docker compose yml project directory docker up dStarting docker php tutorial nginx doneStarting docker php tutorial workspace doneStarting docker php tutorial php fpm done Testingif everything works After rewriting our own docker setup a couple of times I ve come to appreciate a structured way to test if everything works Everything as in are all containers running does host docker internal exist do we see the correct output when sending a request to nginx php fpm are all required php extensions installed This might seem superfluous after all we just defined excatly that in the Dockerfiles but there will come a time when you or someone else need to make changes new PHP version new extensions etc and having something that runs automatically and informs you about obvious flaws is a real time saver You can see the full test file in the repository Since my bash isn t the best I try to keep it as simple as possible The tests can be run viash docker docker test shand should yield something like this Testing service workspace Checking if workspace has a running containerOKTesting PHP version on workspace for php and expect to see PHP OKTesting PHP module xdebug on workspace for php OKTesting PHP module Zend OPcache on workspace for php OKChecking host docker internal on workspace OKTesting service php fpm Makefile and bashrcIn the previous sections I have introduced a couple of commands e g for building and running containers And to be honest I find it kinda challenging to keep them in mind without having to look up the exact options and arguments I would usually create a helper function or an alias in my local bashrc file in a situation like that but that wouldn t be available to other members of the team then and it would be very specific to this one project Instead we ll provide a Makefile as a central reference point Using make as central entry pointPlease refer to the repository for the full Makefile Going into the details of make is a little out of scope for this article so I kindly refer to some articles that helped me get started Makefile for lazy developersWhy you Need a Makefile on your ProjectBoth are written with a PHP context in mind Tip If you are using PhpStorm give the Makefile support plugin a try And don t forget the number one rule A Makefile requires tabs Note If you are using Windows make is probably not available See Install make on Windows MinGW for instructions to set it up The Makefile ist located in the root of the application Since we use a help target that makes the Makefile self documenting we can simply run make to see all the available commands makeUsage make lt target gt Docker Build Infrastructure docker clean Remove the env file for docker docker init Make sure the env file exists for docker docker build from scratch Build all docker images from scratch without cache etc Build a specific image by providing the service name via make docker build CONTAINER lt service gt docker build Build all docker images Build a specific image by providing the service name via make docker build CONTAINER lt service gt docker up Start all docker containers To only start one container use CONTAINER lt service gt docker down Stop all docker containers To only stop one container use CONTAINER lt service gt docker test Run the infrastructure tests for the docker setupAs a new developer your onboarding to get a running infrastructure should now look like this make docker cleanmake docker initmake docker build from scratchmake docker test Install make on Windows MinGW make doesn t exist on Windows and is also not part of the standard installation of MinGW click here to learn how to setup MinGW Setting is up is straight forward but as with everything UI it s easier if you can actually see what I m doing so here s a video The steps are as follows Set up mingw getInstructions www mingw org wiki getting started tocDownload Install and add the bin directory to PATH shortcut systempropertiesadvanced Notes Do not use an installation path that contains spaces The installation path can be different from your MinGW locationInstall mingw make via mingw get install mingw makecreate the file bin make with the contentmingw make exe Note Sometimes Windows won t recognize non exe files so instead of bin make you might need to name the filebin make exe with the same content Open a new shell and type make The output should look something like this make mingw make Keine Targets angegeben und keine ¦make¦ Steuerdatei gefunden Schluss Easy container access via din bashrc helperI ve got one last goodie for working with Docker that I use all the time Logging into a running container via docker exec and the din dshell helper To make this work put the following code in your bashrc filefunction din filter user if n then user user fi shell bash if n then shell fi prefix if expr substr uname s MINGW then prefix winpty fi prefix docker exec it user docker ps filter name filter q head shell The docker ps filter name filter q head part will find partial matches on running containers for the first argument and pass the result to the docker exec command In effect we can log into any container by only providing a minimal matching string on the container name E g to log in the workspace container I can now simply type din works from anywhere on my system Fundamentals on building the containersSince we have now seen the end result let s take a closer look behind the scenes I assume that you are already somewhat familiar with Dockerfiles and have used docker compose to orchestrate multiple services if not check out Persisting image changes with a Dockerfile and Putting it all together Meet docker compose But there are some points I would like to cover in a little more detail Understanding build contextThere are two essential parts when building a container the Dockerfilethe build contextYou can read about the official description in the Dockerfile reference You ll usually see something like this docker build which assumes that you use the current directory as build context and that there is a Dockerfile in the same directory But you can also start the build viadocker build docker f docker nginx Dockerfile └ーuse the Dockerfile at docker nginx Dockerfile └ーuse the docker subdirectory as build contextFor me the gist is this The build context defines the files and folders recursively on your machine that are send from the Docker CLI to the Docker Daemon that executes the build process of a container so that you can reference those files in the Dockerfile e g via COPY Take the following structure for example lt project gt ├ー docker ├ー shared └ーscripts └ー └ーnginx ├ーnginx conf └ーDockerfileAssume that the current working directory is lt project gt If we started a build viadocker build docker nginx f docker nginx Dockerfile the context would not include the shared folder so we wouldn t be able to COPY the scripts subfolder If we randocker build docker f docker nginx Dockerfile however that would make the shared folder available In the Dockerfile itself I need to know what the build context is because I need to adjust the paths accordingly Concrete example for the folder structure above and build triggered via docker build docker f docker nginx Dockerfile FROM nginx build context is docker so the following COPY refers to docker sharedCOPY shared tmp so the following COPY refers to docker nginx nginx confCOPY nginx nginx conf tmpThe build context for all of our containers will be the docker directory so that all build processes have access to the shared scripts and config Yes that also means that the php fpm container has access to files that are only relevant to the mysql container for instance but the performance penalty is absolutely neglectable Plus as long as we don t actively COPY those irrelevant files they won t bloat up our images A couple of notes I used to think that the build context is always tied to the location of the Dockerfile but that s only the default it can be any directorythe build context is actually send to the build process i e you should avoid unnecessary files folders as this mightaffect performance especially on big files iaw don t use as context similar to git Docker knows the concept of a dockerignore fileto exclude files from being included in the build context Dockerfile templateThe Dockerfiles for the containers roughly follow the structure outlined below FROM path to the directory where the Dockerfile lives relative to the build contextARG SERVICE DIR service get the scripts from the build context and make sure they are executableCOPY shared scripts tmp scripts RUN chmod x R tmp scripts set timezoneARG TZ UTCRUN tmp scripts set timezone sh TZ add usersARG APP USER www dataARG APP USER ID ARG APP GROUP APP USER ARG APP GROUP ID APP USER ID RUN tmp scripts create user sh APP USER APP GROUP APP USER ID APP GROUP ID install common softwareRUN tmp scripts install software sh perform any other container specific build stepsCOPY SERVICE DIR config etc service configRUN tmp scripts modify config sh etc service config default conf APP USER APP USER set default work directoryWORKDIR cleanup RUN tmp scripts cleanup sh define ENTRYPOINTENTRYPOINT CMD The comments should suffice to give you an overview so let s talk about the individual parts in detail Setting the timezoneScript set timezone shLet s start with a simple and obvious one Ensuring that all containers use the same system timezone see here and here bin shTZ ln snf usr share zoneinfo TZ etc localtime amp amp echo TZ gt etc timezoneThe script is then called from the Dockerfile viaARG TZ UTCRUN tmp scripts set timezone sh TZ Synchronizing file and folder ownership on shared volumesScript create user shDocker makes it really easy to share files between containers by using volumes For simplicities sake you can picture a volume simply as an additional disk that multiple containers have access to And since it s PHP we re talking about here sharing the same application files is a common requirement e g for php fpm nginx php workers As long as you are only dealing with one container life is easy You can simply chown files to the correct user But since the containers might have a different user setup permissions ownership becomes a problem Checkout this video on Docker amp File Permissions for a practical example in a Laravel application The first thing for me was understanding that file ownership does not depend on the user name but rather on the user id And you might have guessed it Two containers might have a user with the same name but with a different id The same is true for groups btw You can check the id by running id lt name gt e g id www datauid www data gid www data groups www data That s inconvenient but rather easy to solve in most cases because we have full control over the containers and can assign ids as we like using usermod u lt id gt lt name gt and thus making sure every container uses the same user names with the same user ids Things get complicated when the volume isn t just a Docker volume but a shared folder on the host This is usually what we want for development so that changes on the host are immediately reflected in all the containers This issue only affects users with a linux host system Docker Desktop previously known as Docker for Mac Docker for Win has a virtualization layer in between that will effectively erase all ownership settings and make everything shared from the host available to every user in a container We use the following script to ensure a consistent user setup when building a container bin shAPP USER APP GROUP APP USER ID APP GROUP ID new user id exists id APP USER ID gt dev null gt amp echo if new user id exists then gt amp echo ERROR APP USER ID APP USER ID already exists Aborting exit finew group id exists getent group APP GROUP ID gt dev null gt amp echo if new group id exists then gt amp echo ERROR APP GROUP ID APP GROUP ID already exists Aborting exit fiold user id id u APP USER old user exists id u APP USER gt dev null gt amp echo old group id getent group APP GROUP cut d f old group exists getent group APP GROUP gt dev null gt amp echo if old group id APP GROUP ID then create the group groupadd f APP GROUP and the correct id groupmod g APP GROUP ID APP GROUP if old group exists then set the permissions of all old files and folder to the new group find group old group id exec chgrp h APP GROUP true fi fiif old user id APP USER ID then create the user if it does not exist if old user exists then useradd APP USER g APP GROUP fi make sure the home directory exists with the correct permissions mkdir p home APP USER amp amp chmod home APP USER amp amp chown APP USER APP GROUP home APP USER change the user id set the home directory and make sure the user has a login shell usermod u APP USER ID m d home APP USER APP USER s which bash if old user exists then set the permissions of all old files and folder to the new user find user old user id exec chown h APP USER true fifiThe script is then called from the Dockerfile viaARG APP USER www dataARG APP USER ID ARG APP GROUP APP USER ARG APP GROUP ID APP USER ID RUN tmp scripts create user sh APP USER APP GROUP APP USER ID APP GROUP ID The default values can be overridden by passing in the corresponding build args Linux users should use the user id of the user on their host system for Docker Desktop users the defaults are fine Modifying configuration filesFor most services we probably need some custom configuration settings likesetting php ini valueschanging the default user of a service changing the location of logfilesThere are a couple of common approaches to modify application configuration in docker and we are currently trying to stick to two rules provide additional files that override defaults if possible change non static values with a simple search and replace via sed during the container build Providing additional config filesMost services allow the specification of additional configuration files that override the default values in a default config file This is great because we only need to define the settings that we actually care about instead of copying a full file with lots of redundant values Take the php ini file for example It allows to places additional ini files in a specific directory that override the default values An easy way to find this directory is php i grep additional ini php i grep additional ini Scan this dir for additional ini files gt usr local etc php conf dSo instead of providing a full php ini file we will use a zz app ini file instead that only contains the ini settings we actually want to change and place it under usr local etc php conf d Why zz Because Within each directory PHP will scan all files ending in ini in alphabetical order so if we want to ensure that our ini files comes last overriding all previous settings we ll give it a corresponding prefix The full process would look like this place the file in the docker folder e g at docker shared config php conf d zz app inipass the folder as build contextin the Dockerfile use COPY shared config php conf d zz app ini usr local etc php conf d zz app ini Changing non static valuesScript modify config shSome configuration values are subject to local settings and thus should not be hard coded in configuration files Take the memory limit configuration for php fpm as an example Maybe someone in the team can only dedicate a limited amount of memory to docker so the memory limit has to be kept lower than usual We ll account for that fact by using a variable prefixed by instead of the real value and replace it with a dynamic argument in the Dockerfile Example for the aforementioned zz app ini memory limit MEMORY LIMITWe use the following script modify config sh to replace the value bin shCONFIG FILE VAR NAME VAR VALUE sed i e s VAR NAME VAR VALUE CONFIG FILE The script is then called from the Dockerfile viaARG PHP FPM MEMORY LIMIT MRUN tmp scripts modify config sh usr local etc php conf d zz app ini MEMORY LIMIT PHP FPM MEMORY LIMIT where PHP FPM MEMORY LIMIT has a default value of M but can be overridden when the actual build is initiated Installing php extensionsScript install php extensions shWhen php extensions are missing googling will often point to answers for normal linux systems using apt get or yum e g sudo apt get install php xdebug But for the official docker images the recommended way is using the docker php ext configure docker php ext install and docker php ext enable helper scripts Unfortunately some extensions have rather complicated dependencies so that the installation fails Fortunately there is a great project on Github called docker php extension installer that takes care of that for us and is super easy to use FROM php cliADD usr local bin RUN chmod uga x usr local bin install php extensions amp amp sync amp amp install php extensions xdebugThe readme also contains an overview of supported extension per PHP version To ensure that all of our PHP containers have the same extensions we provide the following script bin sh add wgetapt get update yqq amp amp apt get f install yyq wget download helper scriptwget q O usr local bin install php extensions echo Failed while downloading php extension installer exit install all required extensionschmod uga x usr local bin install php extensions amp amp sync amp amp install php extensions xdebug opcache If you re not sure which extensions are required by your application give the ComposerRequireChecker a try Installing common softwareScript install software shThere is a certain set of software that I want to have readily available in every container Since this a development setup I d prioritize ease of use debug over performance image size so this might seem like a little too much I think I m also kinda spoiled by my Homestead past because it s so damn convenient to have everything right at your fingertips Anyway the script is straight forward bin shapt get update yqq amp amp apt get install yqq curl dnsutils gdb git htop iputils ping iproute ltrace make procps strace sudo sysstat unzip vim wget Notes this list should match your own set of go to tools I m fairly open to adding new stuff here if it speeds up thedev workflow But if you don t require some of the tools get rid of them sorting the software alphabetically is a good practice to avoid unnecessary duplicates Don t do this by hand though If you re using an IDE established text editor chances are high that this is either a build in functionality orthere s a plugin available I m using Lines Sorter for PhpStorm Cleaning upScript cleanup shNice and simple bin shapt get cleanrm rf var lib apt lists tmp var tmp var log lastlog var log faillog Using ENTRYPOINT for pre run configurationDocker went back to the unix roots with the do on thing and do it well philosophy which is manifested in the CMD and ENTRYPOINT instructions As I had a hard time understanding those instructions when I started with Docker here s my take at a layman s terms description since a container should do one thing we need to specify that thing That s what we do with ENTRYPOINT Concrete examples a mysql container should probably run the mysqld daemona php fpm container well php fpmthe CMD is passed as the default argument to the ENTRYPOINTthe ENTRYPOINT is executed every time we run a container Some things can t be done during build but only at runtime e g find the IP of the host from within a container see section Providing host docker internal for linux host systems ENTRYPOINT is a good solution for that problemtechnically we can only override an already existing ENTRYPOINT from the base image But We can structure the new ENTRYPOINT like a decorator by adding exec at the end to simulate inheritance from the parent imageTo expand on the last point consider the default ENTRYPOINT of the current PHP php fpm image bin shset e first arg is f or some option if then set php fpm fiexec In the corresponding Dockerfile we find the following instructions ENTRYPOINT docker php entrypoint CMD php fpm That means When we run the container it will pass the string php fpm to the ENTRYPOINT script docker php entrypoint as argument which will then execute it due to the exec instruction at the end docker run name test rm php fpm Feb NOTICE fpm is running pid Feb NOTICE ready to handle connections php fpm is running Hit ctrl c to close the connection docker stop testWe could now override the default CMD php fpm with something else e g a simple echo hello The ENTRYPOINT will happily execute it docker run name test rm php fpm echo hello hello But now the php fpm process isn t started any more How can we echo hello but still keep the fpm process running By adding our own ENTRYPOINT script bin shecho hello exec Full example using stdin to pass the Dockerfile via Heredoc string docker build t my fpm lt lt EOF FROM php fpmRUN touch usr bin my entrypoint sh amp amp echo bin sh gt gt usr bin my entrypoint sh amp amp echo echo hello gt gt usr bin my entrypoint sh amp amp echo exec gt gt usr bin my entrypoint sh amp amp chmod x usr bin my entrypoint sh amp amp cat usr bin my entrypoint sh ENTRYPOINT usr bin my entrypoint sh docker php entrypoint CMD php fpm EOF Note that we added the ENTRYPOINT of the parent image docker php entrypoint as argument to our own ENTRYPOINT script usr bin my entrypoint sh so that we don t loose its functionality And we need to define the CMD instruction explicitly because the one from the parent image is automatically removed once we define our own ENTRYPOINT But It works docker run name test rm my fpmhello Feb NOTICE fpm is running pid Feb NOTICE ready to handle connections Hit ctrl c to close the connection docker stop test Providing host docker internal for linux host systemsScript docker entrypoint resolve docker host ip shIn the previous part of this tutorial series I explained how to build the Docker container in a way that it plays nice with PhpStorm and Xdebug The key parts were SSH access and the magical host docker internal DNS entry This works great for Docker Desktop Windows and Mac but not for Linux The DNS entry doesn t exist there Since we rely on that entry to make debugging possible we will set it manually if the host doesn t exist with the following script inspired by the article Access host from a docker container bin shset eHOST DOMAIN host docker internal check if the host exists this will fail on linuxif dig HOST DOMAIN grep q NXDOMAIN then resolve the host IP HOST IP ip route awk NR print and write it to the hosts file echo HOST IP t HOST DOMAIN gt gt etc hostsfiexec The script is placed at shared docker entrypoint resolve docker host ip sh and added as ENTRYPOINT in the Dockerfile viaCOPY shared scripts tmp scripts RUN mkdir p bin docker entrypoint amp amp cp tmp scripts docker entrypoint bin docker entrypoint amp amp chmod x R bin docker entrypoint ENTRYPOINT bin docker entrypoint resolve docker host ip sh Notes since this script depends on runtime configuration we need to run it as an ENTRYPOINTthere is no need to explicitly check for the OS type we simply make sure that the DNS entry existsand add it if it doesn twe re using dig package dnsutils and ip package iproute which need to be installed during the build time of the container Tip If you need to figure out the package for a specific command give a try See the entry for dig for instance this workaround is only required in containers we want to debug via xdebug Wrapping upCongratulations you made it If some things are not completely clear by now don t hesitate to leave a comment Apart from that you should now have a running docker setup for your local PHP development as well as a nice flow to get started each day In the next part of this tutorial we will add some more containers php workers mysql redis and use a fresh installation of Laravel to make use of them Please subscribe to the RSS feed or via email to get automatic notifications when this next part comes out 2022-06-27 07:46:58
海外TECH DEV Community Pure CSS Woman Wearing Face Mask https://dev.to/asyrafhussin4/pure-css-woman-wearing-face-mask-i55 Pure CSS Woman Wearing Face MaskSpeed Code Video 2022-06-27 07:16:50
海外TECH Engadget Apple's entry-level 13-inch MacBook Pro M2 may have slower SSD speeds than the M1 model https://www.engadget.com/apples-entry-level-13-inch-mac-book-pro-m-2-may-have-slower-ssd-speeds-than-the-m-1-model-073302340.html?src=rss Apple x s entry level inch MacBook Pro M may have slower SSD speeds than the M modelApple s inch GB MacBook Pro M may have worse SSD performance than the equivalent M model according to testing by YouTube sites Max Tech and Created Tech nbsp seen by MacRumors The base model showed around percent slower read speeds MB s compared to MB s with write speeds percent lower nbsp Max Tech opened up the inch MacBook Pro M and found that it only had a single GB NAND flash storage chip instead of two GB chips like the previous M model That would mean the drive can only use two lanes in parallel so performance is restricted to the speed of a single lane nbsp The higher end GB and TB models don t appear to suffer from the issue and many review units like our own shipped in a TB configuration The slower disk speeds on the GB model could affect app loading times file transfers and data fetching Overall performance could also take a hit as the virtual memory used when RAM is full will be slower and the base model only has GB of RAM nbsp It s not clear why Apple changed the configuration on this model though the global chip shortage may be a factor In any case it s something to consider if you re looking at buying the inch MacBook Pro M nbsp 2022-06-27 07:33:16
海外科学 BBC News - Science & Environment Nasa launches first rocket from Australian commercial spaceport https://www.bbc.co.uk/news/world-australia-61947195?at_medium=RSS&at_campaign=KARANGA australia 2022-06-27 07:52:50
金融 金融庁ホームページ 「サステナブルファイナンス有識者会議」(第13回)議事次第について公表しました。 https://www.fsa.go.jp/singi/sustainable_finance/siryou/20220627.html 有識者会議 2022-06-27 09:00:00
ニュース BBC News - Home Birmingham explosion: Woman found dead and man seriously hurt https://www.bbc.co.uk/news/uk-england-birmingham-61946915?at_medium=RSS&at_campaign=KARANGA birmingham 2022-06-27 07:41:30
ニュース BBC News - Home NHS patients to be offered chance to travel for surgery https://www.bbc.co.uk/news/health-61930088?at_medium=RSS&at_campaign=KARANGA nhs 2022-06-27 07:33:27
ニュース BBC News - Home Russia in historic foreign debt default, reports suggest https://www.bbc.co.uk/news/business-61929926?at_medium=RSS&at_campaign=KARANGA interest 2022-06-27 07:25:25
ニュース BBC News - Home Transgender athletes: Tom Daley 'furious' about Fina ban https://www.bbc.co.uk/sport/diving/61948675?at_medium=RSS&at_campaign=KARANGA Transgender athletes Tom Daley x furious x about Fina banOlympic diving champion Tom Daley says he is furious at his sport s world governing body for voting to stop transgender athletes from competing in women s elite events 2022-06-27 07:30:52
ビジネス ダイヤモンド・オンライン - 新着記事 「電気料金の大幅な値上げ」で 東日本大震災以来の電力危機は解決する 【橘玲の日々刻々】 - 橘玲の日々刻々 https://diamond.jp/articles/-/305552 東日本大震災 2022-06-27 17:00:00
北海道 北海道新聞 5月の外食売上高20・4%増 連休3年ぶり行動制限なく https://www.hokkaido-np.co.jp/article/698589/ 外食売上高 2022-06-27 16:49:00
北海道 北海道新聞 ベラルーシがロシア側面支援強化 攻撃拠点に、参戦はせず https://www.hokkaido-np.co.jp/article/698588/ 長期化 2022-06-27 16:49:00
北海道 北海道新聞 電力逼迫、東電管内で注意報継続 気温上昇、冷房需要が高止まり https://www.hokkaido-np.co.jp/article/698587/ 経済産業省 2022-06-27 16:46:00
北海道 北海道新聞 米、アラブ諸国と秘密会合 対イラン防衛協議と報道 https://www.hokkaido-np.co.jp/article/698578/ 防衛 2022-06-27 16:42:00
北海道 北海道新聞 ソフトバンク、和田ら8人が陽性 チーム活動は継続 https://www.hokkaido-np.co.jp/article/698576/ 嘉弥真新也 2022-06-27 16:31:00
北海道 北海道新聞 <横田教授の「コロナ」チェック>新規感染、全道で順調に減少 混雑した場所ではマスク着用など徹底を https://www.hokkaido-np.co.jp/article/698566/ 新型コロナウイルス 2022-06-27 16:30:00
北海道 北海道新聞 海洋放出「断固反対」決議手渡す 全漁連会長、経産省に https://www.hokkaido-np.co.jp/article/698573/ 全国漁業協同組合連合会 2022-06-27 16:24:00
IT 週刊アスキー Switch/PS5/PS4『ディスコ エリジウム ザ ファイナル カット』の独特の会話システムを紹介! https://weekly.ascii.jp/elem/000/004/095/4095929/ nintendo 2022-06-27 16:55:00
IT 週刊アスキー ジョナサン行ったらこれ食べよ! 暑いに夏にぴったり「トムヤム冷麺」 https://weekly.ascii.jp/elem/000/004/095/4095881/ 盛岡冷麺 2022-06-27 16:30:00
IT 週刊アスキー スマホ社員証「Smart Me」で利用者の所属を証明する機能の提供を開始 https://weekly.ascii.jp/elem/000/004/095/4095924/ smartme 2022-06-27 16:30:00
IT 週刊アスキー かわいいダヤンのグッズを買いに行こう! 紀伊國屋書店 ららぽーと横浜店にて「猫のダヤン」グッズフェアが7月18日まで開催中 https://weekly.ascii.jp/elem/000/004/095/4095925/ 紀伊國屋書店 2022-06-27 16:30:00
マーケティング AdverTimes アミューズ、広報宣伝部を設置(22年7月1日付) https://www.advertimes.com/20220627/article388279/ 事業活動 2022-06-27 07:46:11

コメント

このブログの人気の投稿

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2020-12-01 09:41:49 RSSフィード2020-12-01 09:00 分まとめ(69件)