In fact, I don't use Tinkerwell recently because it keeps costing me money to update.
If you want to test the direct ssh host, it’s done, right? 🙄
devin@m1Max:~$ssh www
Last login: Sat Dec 10 09:39:03 2022 from 172.23.0.1
dlaravel@1defe94ae59d:~$ tinker
Psy Shell v0.11.9 (PHP 8.1.11 — cli) by Justin Hileman
>
My hosts are all Laravel environments in SSH containers, basically tinkers everywhere.
In the phpenv environment, the last two lines have directly built in the aliases of artisan and tinker.
https://github.com/DevinY/phpenv/blob/main/dockerfiles/bash_aliases
alias artisan='/usr/local/bin/php /var/www/html/artisan'
alias tinker='/usr/local/bin/php /var/www/html/artisan tinker'
Here is the old information
foreword
D-Laravel has added the ssh image, which means that we can use Tinkerwell in D-Laravel's docker environment.
Of course, I believe that the use of ssh is more than that.
If you haven't heard of Tinkerwell, you can refer to the official website Demo:
https://tinkerwell.app/
Image about build ssh (not necessary)
We can use dlaravel's
dockerfiles/fpm/Dockerfile_php_ssh
Build our own image, simple execution...
#在D-Laravel的目錄中
cd dockerfiles/fpm
./build ssh
If you want a different php version, you can adjust the first line of the Dockerfile_php_ssh file yourself.
FROM php:7.4.2-fpm
ARG user
#Install ssh environment
ENV OSSH_USER ${user:-dlaravel}
RUN apt-get update&&apt-get install -y openssh-server git pwgen
RUN mkdir /var/run/sshd
slightly.....
Or use official instructions to build your own image
docker build -t -f Dockerfile_php_ssh .
If you are sharp-eyed, you may find that in the build.sh command, the official build command has also been listed for your reference.
The build command defaults to find the Dockerfile, but because we use a non-default file, there is an extra -f to specify the file, and the last "." represents the current directory.
Switch the PHP plus ssh environment on Docker
On D-Laravel's simple bash, switching to the ssh environment is very simple, if you are already a D-Laravel user, you may have guessed it.
./console ssh
This command will create a soft link in the D-Laravel directory, which we can confirm through the ./console link command.
Let's take a look at the contents of docker-compose-ssh.yml
version: '3.6'
services:
#=== web service ========================
web:
image: nginx
dns: 8.8.8.8
ports:
# normal
- "80:80"
- "443:443"
- "2020:22"
volumes:
- ./sites:/var/www/html:cached
- ./etc:/etc/nginx/conf.d
- ./var/log/web:/var/log/nginx
hostname: web
networks:
- dlaravel_net
#=== php service ============================
php:
network_mode: "service: web"
image: deviny/fpm:7.4.2ssh
volumes:
- ./etc/php:/usr/local/etc/php/conf.d
- ./sites:/var/www/html:cached
- ./etc/php-fpm.d/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ~/.ssh:/home/dlaravel/.ssh
- ./etc/cache:/home/dlaravel/.composer/cache
environment:
-TZ=Asia/Taipei
#=== db service =============================
db:
image: mysql:8.0.18
command: --default-authentication-plugin=mysql_native_password
hostname: db
ports:
- "127.0.0.1:3306:3306"
volumes:
- ./etc/mysql/conf.d:/etc/mysql/mysql.conf.d
- ./data:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD="yes"
-TZ=Asia/Taipei
networks:
- dlaravel_net
#=== top-level netowks key ========================
networks:
dlaravel_net:
In the above Yaml file, please focus on the php container service (php:).
1. port
- "2020:22"
Didn’t you mean to focus on the setting of php:container service? How is this 2020:22 in web service (web:)?
Please note that the php network mode here is adopted in the setting of D-Laravel
network_mode: servce:web
This represents the connection port he opened, which will be opened on the web service, so the -port setting is placed in web:.
If you are new to docker, please remind me that the 2020 on the left of the colon is the connection port of the host, which means that the host who executes Docker is our own computer. As long as there is no conflict, you can adjust it according to your needs.
The 22 on the right side of the colon is the connection port opened in the container, which is basically fixed and cannot be adjusted.
2. The image part of ssh uses the PHP version 7.4.2 and has the ssh function.
image: deviny/fpm:7.4.2ssh
3. Mount, volumes: project under php:
- ~/.ssh:/home/dlaravel/.ssh
By default, D-Laravel directly mounts the .ssh folder (~/.ssh) in our own home directory. Of course, you can adjust it according to your needs.
SSH public key authentication The ssh service built by D-Laravel can only use public key authentication to log in, and passwords are not available.
OpenSSH will have two keys, one is the private key without .pub, and the other is the private key.
First, we go to the ~/.ssh directory first, and the command is as follows:
cd ~/.ssh
However, you may get an error message that the .ssh directory cannot be found
cd: no such file or directory: /Users/devin/.ssh
If you get the error above, the directory does not exist, don't worry, it means you haven't created any OpenSSH key, you can use ssh-keygen to generate one.
I wanted to give the tinkerwell a dedicated key, so, here's what I did.
cd ~/.ssh
ssh-keygen -C "tinkerwell"
The actual execution picture is as follows: ( very important, do not press Enter directly when asking for storage, otherwise your own id_rsa will be overwritten, if you have created it before )
For the part that asks for the passphrase of the key password, you can press enter to leave it blank.
Execute ls tinkerwell, and you will find that the key pair of tinkerwell has been established in our directory.
$ls tinkerwell*
tinkerwell tinkerwell.pub
We can use the command below to redirect and quickly add the public key to authorized_keys
cat tinkerwell.pub >> authorized_keys
Test SSH login to php container
Through the ssh command, quickly test whether you can use ssh to connect to the container
ssh -i ~/.ssh/tinkerwell dlaravel@127.0.0.1 -p 2020
Parameter Description:
-i specifies the private key we want to use. In the above setting, we have added the tinkerwel.pub public key to authorized_keys.
-p specifies a non-standard connection port, and D-Laravel will open the port in 2020, so it is specified to connect to 2020 here.
Successfully logged in, we can exit with Ctrl+d.
Tinkerwell setting point Select the fourth icon on the left in the figure below, ssh connect, to set:
Next, let’s try tinkerwell. When selecting the key, because ~/.ssh is a hidden folder, so in the MacOS system, we can use
shift+cmd+g, to specify the path, and select our key
Let's try it out:
It's done, and Tinkerwell has been successfully implemented in the project.
No Comment
Post your comment