Essential Terminal Commands for Docker, CakePHP, and App Development | Eduardo Rocha

Imagem de Eduardo Rocha
Published by:
Eduardo Rocha

Share on social media

16 de fev. de 2025

Terminal Commands to Assist in Developing Applications with Docker, CakePHP, and Other Tools

In this post I will demonstrate some basic commands that will help you develop your project with different tools.

Docker + Docker Compose

1) To upload a project to your local machine:

docker-compose up -d

2) To find out which projects are uploaded to your local machine:

docker ps

3) To take down the project on your local machine:

docker-compose down

4) To rebuild your docker project:

docker-compose build --no-cache

5) To free up more space on your computer, delete the containers created using this command:

docker system prune -a

6) How to enter your project machine:

docker exec -it nome-do-seu-projeto_php_1

7) To exit the docker machine:

exit

CakePHP 3.x

Before you start running the commands below, you must log into your project machine in listing 6) above.

8) To create a new migration you run the following command:

bin/cake migrations create NomedasuaMigracao

9) If you are on Linux/Ubuntu, run the command that gives you permission to edit the file. Remember that you must do it outside the docker machine in listing 7):

sudo chown nome-do-seu-user:nome-do-seu-user config/Migrations -R

10) This is a Basic example of Table creation using migration

table('produtos');
        $produtos
            ->addColumn('nome', 'string', [
                'null' => true,
                'default' => null,
                'limit' => 255,
            ])
            ->addColumn('slug', 'text', [
                'null' => true,
                'default' => null,
                'limit' => MysqlAdapter::TEXT_LONG,
            ])
            ->addColumn('image', 'string', [
                'null' => true,
                'default' => null,
                'limit' => 255,
            ])
            ->addColumn('status', 'boolean', [
                'null' => true,
            ])
            ->addColumn('created', 'datetime', [
                'null' => true,
                'timezone' => true,
            ])
            ->addColumn('modified', 'datetime', [
                'null' => true,
                'timezone' => true,
            ])
            ->create();
    }
}

11) To run the migration, follow the command below:

bin/cake migrations migrate

12) To undo a migration:

bin/cake migrations rollback

13) To update an attribute with the migration. You have the option to do a Rollback in listing 12) if it is the last migration made and modify the created migration or if there are several other migrations in front you can update by creating a new migration in listing 8 and then you can use this example model:

table('produtos');
        $produtos
            ->addColumn('data_publicacao', 'datetime', [
                'null' => true,
                'timezone' => true,
                'default' => null,
            ])
            ->update();
    }
}

Then you update using Listing 11) to update the database.

14) To revert back to CakePHP 3.x Composer version with the docker machine open:

composer self-update --1

15) To install CakePHP Composer 3.x

composer install

16) To clear the route cache in CakePHP 3.x

bin/cake cache clear_all

17) Update ACL permissions

bin/cake acl_extras aco_sync

18) Compile styles if you are using the AssetCompress plugin in CakePHP 3.x

bin/cake AssetCompress.AssetCompress build --force

19) Compile styles if you are using the AssetCompress plugin in CakePHP 2.x

Console/cake AssetCompress.asset_compress build -f

20) If you have the AuditLog Plugin, this is the command to run its exclusive migration in CakePHP 3.x | 4.x

bin/cake migrations migrate -p AuditLog

These are some of the commands I use most, I hope they help you.

Image ForPixabay: https://www.pexels.com/pt-br/foto/codigo-c-de-computador-276452/

Related Tags

Share on social media