by Devin Yang
(This article was automatically translated.)

Published - 4 years ago ( Updated - 1 year ago )

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
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.

 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


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:

Image about build ssh (not necessary)

We can use dlaravel's
Build our own image, simple execution...

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

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 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'
#=== web service ========================
image: nginx
# normal
- "80:80"
- "443:443"
- "2020:22"
- ./sites:/var/www/html:cached
- ./etc:/etc/nginx/conf.d
- ./var/log/web:/var/log/nginx
hostname: web
- dlaravel_net

#=== php service ============================
network_mode: "service: web"
image: deviny/fpm:7.4.2ssh
- ./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

#=== db service =============================
image: mysql:8.0.18
command: --default-authentication-plugin=mysql_native_password
hostname: db
- ""
- ./etc/mysql/conf.d:/etc/mysql/mysql.conf.d
- ./data:/var/lib/mysql
- dlaravel_net

#=== top-level netowks key ========================

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*

We can use the command below to redirect and quickly add the public key to authorized_keys

 cat >> 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@ -p 2020

Parameter Description:
-i specifies the private key we want to use. In the above setting, we have added the 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.


Tags: docker tinkerwell tinker laravel

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


How to update or rebuild D-Laravel's FPM Image

Sometimes, the docker image will undergo some corrections or add more plug-ins, how do we update the image in the computer? It's very simple, use docker pull [use the image], if you want to create your own image is also feasible...


Unable to ping host.docker.internal on Linux

You can check with docker version, confirm that the version is Docker v20.10+, you can add extra_hosts as follows:


A brief introduction to the phpenv container environment I built

I don't have time to shoot an introduction video, so I'll just grab some pictures and introduce the container environment deviny/phpenv I use. can be regarded as an evolutionary version of my previous D-Laravel open source project, conceptually extending the use of many Dlaravel operation methods. The update of the container tends to be controlled by the user to build his own image, so I am not very good at changing the version number. In fact, the php version number of D-Laravel seems to have not been changed for a long time:p