Skip to main content

Setting up a new project in Docker and VS Code.

Using Terminal, go to your Sites directory and create a new directory using the mkdir command.  In this instance I'm going to create a new directory titled ADCE

shortcut command to access the Sites directory

cd ~/Sites

Create the new directory

mkdir ADCE

Go in to the new directory

cd ADCE

Run the devcontainer command

devcontainer

This will require you to respond to prompts.  I'll be setting up on PHP 7.4, Drupal 9, MySQL 5.7 and SOLR 8.x:

ADCE devcontainer 
prompt: Where should the .devcontainer folder go?:  (.) 
prompt: What should the docroot be?:  (web) 
prompt: What do you want the .test domain to be?:  (ADCE) 
Which version of PHP would you like?
> PHP 7.4
  PHP 7.3
  PHP 7.2
  PHP 7.1
  PHP 7.0
Which framework will you be developing in?
> Drupal 9
  Drupal 8
  Drupal 7
  Laravel
  Wordpress
  Magento 2
  None
Which version of MySQL would you like?
> MySQL 5.7
  MySQL 8.0
  None
Which version of Memcached would you like?
  Memcached 1.5
> None
Which version of SOLR would you like?
> SOLR 8.x
  SOLR 7.x
  SOLR 6.x
  SOLR 5.x
  SOLR 4.x
  None
Which version of NodeJS would you like?
> Latest
  Node 13.x
  Node 12.x
  Node 11.x
  Node 10.x
  Node 9.x


    Config complete:
    
    --------------

    Recommended Drupal 8 setup: curl -sL https://icon-drupal-bootstrap.netlify.com/project-setup.sh | bash -
    
    --------------

    MySQL inside your app:
    MySQL Host: mysql
    MySQL Username: root
    MySQL Password: root

    MySQL from your desktop (Sequel Pro) via SSH tunnel:
    SSH Host: 127.0.0.1
    SSH Port: 22222
    SSH Username: root
    SSH Password: root
    MySQL Host: ADCE_mysql_1
    
    --------------

    SOLR Host: solr
    SOLR Port: 8983

    To create your core, add your config files to: .devcontainer/solr/local/ACDE
    Then log into the SOLR Admin URL and add a core at: local/ACDE
    SOLR Admin URL: http://ACDE-solr.test
    
    --------------

    Web URL: https://ACDE.test
    Docroot: /Users/{yourname}/Sites/ACDE/web

    You should run in your project (within the docker):
    composer require-dev phpcompatibility/php-compatibility

    Project ready to open in vscode with devcontainer.

 

Open in VS Code

code .

Now you are in VS Code and click open in container:

In the Terminal area in VS Code run 

composer create-project drupal-composer/drupal-project:9.x-dev some-dir --no-interaction

This command will set-up Drupal 9 in this directory.

Now set-up the MySQL db.  First confirm which MySQL is being used by

which mysql

Response

/usr/bin/mysql

All good, set the MySQL user and password

mysql -u root -proot -h mysql

Create the database, in this instance it will be called ACDE_drupal

create database ACDE_drupal;
exit;​​​​​​​

​​​​​​​Move the content in some-dir, to the previous directory using the mv command.  First grab all of the files and directories and move them

mv some-dir/* .

Second, grab all of the hidden files / directories

mv some-dir/.* . (n when prompted for ..)

N​​​​​​​ow the some-dir directory is empty.  So it is time to remove the temporary directory some-dir

rm -rf some-dir

Initialise Git

git init

Ensure proxy running... In Docker

open ACDE.test

Now you will be prompted to set-up a new Drupal 9 installation on your local environment.  When you complete the database credentials, use the credentials that were set above:

db: u: root, p: root, db: drupal, host: mysql

Related articles

Andrew Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...