{"id":848,"date":"2022-01-01T15:48:51","date_gmt":"2022-01-01T15:48:51","guid":{"rendered":"https:\/\/mklasen.com\/?p=848"},"modified":"2022-01-01T15:48:53","modified_gmt":"2022-01-01T15:48:53","slug":"adding-and-using-wp-cli-in-a-docker-compose-setup","status":"publish","type":"post","link":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/","title":{"rendered":"Adding and using WP-CLI in a docker-compose setup"},"content":{"rendered":"\n

For most of my WordPress projects I use my own Alcedo WordPress<\/a> workflow. With some extra scripts, creating a new site is as easy as running 'create site.c7'<\/code>in the terminal. This sets up a full WordPress install with local domains and certificates.<\/p>\n\n\n\n

But, in this case i’m using a different setup in which I use the default wordpress:php8.0<\/code> docker image. As i’m using the standard setup, I also wanted to use the default wordpress:cli<\/code> docker image.<\/p>\n\n\n\n

How does that work?<\/h3>\n\n\n\n

As they say, an image says more then a thousands words. But, since text in images can’t be copied, I’ll copy\/paste the two services below:<\/p>\n\n\n\n

  wp:\n    container_name: ${NAME}-wp\n    depends_on:\n      - db\n    image: wordpress:php8.0\n    user: 1000:1000\n    volumes:\n      - .\/app\/www\/content\/plugins:\/var\/www\/html\/wp-content\/plugins\n      - .\/app\/www\/content\/mu-plugins:\/var\/www\/html\/wp-content\/mu-plugins\n      - .\/app\/www\/content\/themes:\/var\/www\/html\/wp-content\/themes\n      - uploads:\/var\/www\/html\/wp-content\/uploads:rw\n      - wordpress:\/var\/www\/html\n    ports:\n      - \"8000:80\"\n    environment:\n      WORDPRESS_DB_HOST: ${NAME}-db:3306\n      WORDPRESS_DB_USER: ${DB_USER}\n      WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}\n      WORDPRESS_DB_NAME: ${DB_NAME}\n      WORDPRESS_DEBUG: 1\n      VIRTUAL_HOST: \"${SITE_DOMAIN}\" # Used for nginx-proxy\n      VIRTUAL_PORT: 80 # Used for nginx-proxy\n      LETSENCRYPT_HOST: \"${SITE_DOMAIN}\" # Used for nginx-proxy\n      WORDPRESS_CONFIG_EXTRA: |\n        \/* Multisite *\/\n        define( 'MULTISITE', true );\n        define( 'SUBDOMAIN_INSTALL', true );\n        define( 'DOMAIN_CURRENT_SITE', 'sitec7' );\n        define( 'PATH_CURRENT_SITE', '\/' );\n        define( 'SITE_ID_CURRENT_SITE', 1 );\n        define( 'BLOG_ID_CURRENT_SITE', 1 );\n    expose:\n      - \"80\"\n  \n  wpcli:\n    container_name: ${NAME}-cli\n    depends_on:\n      - wp\n    image: wordpress:cli\n    user: 1000:1000\n    command: tail -f \/dev\/null\n    volumes:\n      - wordpress:\/var\/www\/html\n    environment:\n      WORDPRESS_DB_HOST: ${NAME}-db:3306\n      WORDPRESS_DB_USER: ${DB_USER}\n      WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}\n      WORDPRESS_DB_NAME: ${DB_NAME}\n    profiles:\n      - dev<\/code><\/pre>\n\n\n\n

As you see, both images use the same volume and environment setup. This allows you to run commands like:<\/p>\n\n\n\n

docker exec site-cli wp --info<\/code><\/pre>\n\n\n\n

and<\/p>\n\n\n\n

docker exec site-cli wp search-replace \"test\" \"test1\" --dry-run<\/code><\/pre>\n\n\n\n

Want to make it even easier? Set an alias for docker exec site-cli wp<\/code> so that you can run something like sitewp --info<\/code>. In my own development environment, my folders are named the same as my container. When you change directory, and the directory has an .env<\/code> file, an alias is set for wp<\/code> and links to the correct container.<\/p>\n\n\n\n

Happy developing!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"

For most of my WordPress projects I use my own Alcedo WordPress workflow. With some extra scripts, creating a new site is as easy as running ‘create site.c7’in the terminal. This sets up a full WordPress install with local domains and certificates. But, in this case i’m using a different setup in which I use […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[1],"tags":[],"acf":[],"yoast_head":"\nAdding and using WP-CLI in a docker-compose setup - Marinus Klasen<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding and using WP-CLI in a docker-compose setup - Marinus Klasen\" \/>\n<meta property=\"og:description\" content=\"For most of my WordPress projects I use my own Alcedo WordPress workflow. With some extra scripts, creating a new site is as easy as running 'create site.c7'in the terminal. This sets up a full WordPress install with local domains and certificates. But, in this case i’m using a different setup in which I use […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/\" \/>\n<meta property=\"og:site_name\" content=\"Marinus Klasen\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/marinus.klasen\" \/>\n<meta property=\"article:author\" content=\"http:\/\/facebook.com\/marinus.klasen\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-01T15:48:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-01T15:48:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mklasen.com\/content\/uploads\/2020\/03\/cropped-cropped-mklasen-logo-margin-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinus Klasen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/marinusklasen\" \/>\n<meta name=\"twitter:site\" content=\"@marinusklasen\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinus Klasen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/\"},\"author\":{\"name\":\"Marinus Klasen\",\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29\"},\"headline\":\"Adding and using WP-CLI in a docker-compose setup\",\"datePublished\":\"2022-01-01T15:48:51+00:00\",\"dateModified\":\"2022-01-01T15:48:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/\"},\"wordCount\":189,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29\"},\"articleSection\":[\"General\"],\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/\",\"url\":\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/\",\"name\":\"Adding and using WP-CLI in a docker-compose setup - Marinus Klasen\",\"isPartOf\":{\"@id\":\"https:\/\/mklasen.com\/#website\"},\"datePublished\":\"2022-01-01T15:48:51+00:00\",\"dateModified\":\"2022-01-01T15:48:53+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mklasen.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"General\",\"item\":\"https:\/\/mklasen.com\/general\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Adding and using WP-CLI in a docker-compose setup\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mklasen.com\/#website\",\"url\":\"https:\/\/mklasen.com\/\",\"name\":\"Marinus Klasen\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mklasen.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"nl-NL\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29\",\"name\":\"Marinus Klasen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/mklasen.com\/content\/uploads\/2021\/01\/DONE1171.jpg\",\"contentUrl\":\"https:\/\/mklasen.com\/content\/uploads\/2021\/01\/DONE1171.jpg\",\"width\":1500,\"height\":1000,\"caption\":\"Marinus Klasen\"},\"logo\":{\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/image\/\"},\"description\":\"Marinus has been working in software\/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge. Marinus Klasen on Twitter\",\"sameAs\":[\"http:\/\/facebook.com\/marinus.klasen\",\"https:\/\/nl.linkedin.com\/in\/marinusklasen\",\"https:\/\/twitter.com\/http:\/\/twitter.com\/marinusklasen\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding and using WP-CLI in a docker-compose setup - Marinus Klasen","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/","og_locale":"nl_NL","og_type":"article","og_title":"Adding and using WP-CLI in a docker-compose setup - Marinus Klasen","og_description":"For most of my WordPress projects I use my own Alcedo WordPress workflow. With some extra scripts, creating a new site is as easy as running 'create site.c7'in the terminal. This sets up a full WordPress install with local domains and certificates. But, in this case i’m using a different setup in which I use […]","og_url":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/","og_site_name":"Marinus Klasen","article_publisher":"http:\/\/facebook.com\/marinus.klasen","article_author":"http:\/\/facebook.com\/marinus.klasen","article_published_time":"2022-01-01T15:48:51+00:00","article_modified_time":"2022-01-01T15:48:53+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/mklasen.com\/content\/uploads\/2020\/03\/cropped-cropped-mklasen-logo-margin-1.png","type":"image\/png"}],"author":"Marinus Klasen","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/marinusklasen","twitter_site":"@marinusklasen","twitter_misc":{"Written by":"Marinus Klasen","Est. reading time":"2 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/#article","isPartOf":{"@id":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/"},"author":{"name":"Marinus Klasen","@id":"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29"},"headline":"Adding and using WP-CLI in a docker-compose setup","datePublished":"2022-01-01T15:48:51+00:00","dateModified":"2022-01-01T15:48:53+00:00","mainEntityOfPage":{"@id":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/"},"wordCount":189,"commentCount":2,"publisher":{"@id":"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29"},"articleSection":["General"],"inLanguage":"nl-NL","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/","url":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/","name":"Adding and using WP-CLI in a docker-compose setup - Marinus Klasen","isPartOf":{"@id":"https:\/\/mklasen.com\/#website"},"datePublished":"2022-01-01T15:48:51+00:00","dateModified":"2022-01-01T15:48:53+00:00","breadcrumb":{"@id":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mklasen.com\/adding-and-using-wp-cli-in-a-docker-compose-setup\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mklasen.com\/"},{"@type":"ListItem","position":2,"name":"General","item":"https:\/\/mklasen.com\/general\/"},{"@type":"ListItem","position":3,"name":"Adding and using WP-CLI in a docker-compose setup"}]},{"@type":"WebSite","@id":"https:\/\/mklasen.com\/#website","url":"https:\/\/mklasen.com\/","name":"Marinus Klasen","description":"","publisher":{"@id":"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mklasen.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"nl-NL"},{"@type":["Person","Organization"],"@id":"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29","name":"Marinus Klasen","image":{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/mklasen.com\/#\/schema\/person\/image\/","url":"https:\/\/mklasen.com\/content\/uploads\/2021\/01\/DONE1171.jpg","contentUrl":"https:\/\/mklasen.com\/content\/uploads\/2021\/01\/DONE1171.jpg","width":1500,"height":1000,"caption":"Marinus Klasen"},"logo":{"@id":"https:\/\/mklasen.com\/#\/schema\/person\/image\/"},"description":"Marinus has been working in software\/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge. Marinus Klasen on Twitter","sameAs":["http:\/\/facebook.com\/marinus.klasen","https:\/\/nl.linkedin.com\/in\/marinusklasen","https:\/\/twitter.com\/http:\/\/twitter.com\/marinusklasen"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"Marinus Klasen","author_link":"https:\/\/mklasen.com\/author\/mklasen\/"},"_links":{"self":[{"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/posts\/848"}],"collection":[{"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/comments?post=848"}],"version-history":[{"count":1,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/posts\/848\/revisions"}],"predecessor-version":[{"id":849,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/posts\/848\/revisions\/849"}],"wp:attachment":[{"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/media?parent=848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/categories?post=848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/tags?post=848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}