Since we built the environment using docker, we will introduce the procedure. Since I built the environment with docker for the first time, I hope it will be helpful as much as possible.
| environment | version |
|---|---|
| PHP | 7.0.27 |
| FW | CakePHP3.2.13 |
| Apache | 2.2.15 |
| OS | CentOS6.9 |
| DB | MySQL5.6.39 |
-/
|- docker-compose.yml
|- docker
|- db
| |- Dockerfile
| |- files
| |- entry.sh
| |- my.cnf
|
|
|- web
|- Dockerfile
|- files
|- composer.phar
|- dev.conf
|- php.ini
|- ssl.conf
-/ |- project |- docker-compose.yml |- docker
Create an image and start the container before entering the container. Do the following on the command line:
docker build // You can get the image from docker file by building.
$ docker-compose up -d // Start the container.
You can build and start the container at the same time with the following command.
$ docker-compose up -d --build // Start the container by building the image.
$ docker ps //起動中のコンテナの確認
$ docker-compose up // You cannot work in the same terminal because you are starting the container in the terminal.$ docker-compose up -d // Since the container is started in the background, you can work in the same terminal.
Enter the container with the following command.
$ docker exec -it CONTAINER ID /bin/bash // The CONTAINER ID can be confirmed by doing docker ps.
service httpd start Apache startup service httpd stop Apache stopped service httpd restart Apache restart /etc/init.d/httpd status Apache status check
I was able to execute the following. By the way, composer install was done in the project folder.
compser install
If you access in this state, a database error will be displayed in the browser. The content of the error is that no such (connected) file can be found.
database error(SQLSTATE[HY000] [2002] No such file or directory
service mysqld status //mysqlの起動状態の確認 service mysqld start //mysqlの起動
Confirm your initial username and password before logging in. Check mysqld.log in the DB container.
cat mysqld.log
Get the user name password written in A temporary password is ~. Username: root
Log in to the database.
docker exec -it container ID mysql -u root -p
Reset password-> Create database-> Create table.
-/
|- project
|- config
|-app.php
How to write app.php can be found by searching on the net. This time, I copied the file used elsewhere and edited the contents. I mainly touch the database.
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
/**
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
*/
//'port' => 'non_standard_port_number',
'username' => 'root',
'password' =>'password set when creating the database',
'database' =>'Password set when creating database',
'port' => port number,
'encoding' => 'utf8',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
cat mysqld.log Get the password written in A temporary password is -> Restart mysql in db container, login-> password reset-> create database-> create table->
I searched for localhost in my browser and it opened successfully.
Understand the contents of docker-compose.yml https://futureys.tokyo/lets-understand-contents-of-docker-compose-yml/
Docker compose Kotobuki Hands-on https://qiita.com/TsutomuNakamura/items/7e90e5efb36601c5bc8a
How to write and use Dockerfile https://blog.codecamp.jp/docker-file-how-to
Enter the shell of a running docker container https://qiita.com/sekizo/items/27cc9b406332afc674f6
Database creation https://noumenon-th.net/programming/2019/04/01/docker-entrypoint-initdb01/
How to write permissions to set with chmod https://qiita.com/irasally/items/6ebc3c68e22905fb7330
Recommended Posts