Skip to content

Commit 54ef4d3

Browse files
author
Alan Kent
committed
Changed from 'docker-compose exec web bash' to SSH.
Most Windows CMD prompts where exiting docker exec when you press CTRL+Z. SSH behaves more reliably.
1 parent c7b578c commit 54ef4d3

File tree

6 files changed

+64
-21
lines changed

6 files changed

+64
-21
lines changed

README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ ready to get up and going with DevBox.
6363

6464
* Install a recent version of Docker from http://docker.com/. Docker is
6565
available for Windows, Mac, and Linux.
66-
* As part of the Docker installation process, on Windows 10 you may need to
66+
* As part of the Docker installation process on Windows 10, you may need to
6767
turn on Hyper-V and then grant Docker access to the `C:` drive for Docker to
6868
mount volumes correctly. This is described in the Docker documentation.
6969
* On Windows, it can be useful to install "Git Bash"
70-
(https://git-for-windows.github.io/). As well as Git, it includes a terminal
71-
emulator as well as a useful collection of Linux commands.
70+
(https://git-for-windows.github.io/). As well as Git, it includes SSH, an
71+
xterm terminal emulator, and a useful collection of commonly used Linux
72+
commands.
7273

7374
## Setting Up a New Environment
7475

@@ -133,13 +134,26 @@ You can check what containers exist using
133134

134135
To get a bash prompt inside the web container, use
135136

136-
docker-compose exec web bash
137+
docker-compose exec --user magento2 web bash
137138

138139
You should see a shell prompt of `m2$`. If you are using a Git Bash window on
139140
Windows, you may see an error message saying you need to use `winpty`. In that
140141
case you must use the following command to create a bash prompt.
141142

142-
winpty docker-compose exec web bash
143+
winpty docker-compose exec --user magento2 web bash
144+
145+
In general this works well, but on Windows the 'exec' command will exit if you
146+
press CTRL+Z. If you like using CTRL+Z in Linux, this is rather annoying, so
147+
SSH access is recommended instead.
148+
149+
To enable SSH support (recommended), make sure port 22 is uncommented in
150+
`docker-compose.yml` and mapped to an available port number. For example, use
151+
"2222:22" to use port 2222 to avoid colliding with any local SSH daemons.
152+
You must then use the `-p 2222` argument to specify the port number. The
153+
`m2ssh` command (BAT and bash versions available) automatically picks up the
154+
port number from your `docker-compose.yml` file.
155+
156+
m2ssh
143157

144158
### 4. Install Magento
145159

@@ -167,7 +181,7 @@ will copy files on your laptop into the web container when Unison is started.
167181

168182
Log into the web container.
169183

170-
docker-compose exec web bash
184+
m2ssh
171185

172186
Create a new project under `/var/www/magento2`. Update the project edition and
173187
version number as appropriate. This example uses Magento Open Source (formerly
@@ -187,7 +201,7 @@ repository on a hosting provider such as GitHub or BitBucket.
187201

188202
Log into the web container:
189203

190-
docker-compose exec web bash
204+
m2ssh
191205

192206
Check out the project from inside the container into the `magento2` directory.
193207

@@ -213,7 +227,7 @@ developers.)
213227

214228
Log into the web container:
215229

216-
docker-compose exec web bash
230+
m2ssh
217231

218232
Make a local clone of Magento Open Source (formerly Community Edition). Use
219233
your own fork repository URL if appropriate.
@@ -240,7 +254,7 @@ to use. The following creates the database `magento2`.
240254

241255
Log on to the bash prompt inside the web container
242256

243-
docker-compose exec web bash
257+
m2ssh
244258

245259
Run the following commands to create a MyQL database for the web site to use
246260
(plus a second database for integration tests to use).
@@ -313,13 +327,13 @@ using the START command or by double clicking the BAT file via Windows file
313327
explorer. This will automatically retrieve a copy of the `unison.exe` binary
314328
from the web container. Close the window to kill Unison.
315329

316-
START m2devbox-unison-sync.bat
330+
START m2unison.bat
317331

318332
Mac binaries and a shell script are also provided. It is recommended to run the
319333
sync shell script in a separate Terminal window so you can refer to its output
320334
if you ever need to do troubleshooting.
321335

322-
./m2devbox-unison-sync.sh
336+
./m2unison
323337

324338
This shell script cannot be used on Linux, only Mac OSX. Use volume mounting on
325339
Linux (not Unison).

docker-compose.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ services:
88
web:
99
restart: always
1010
image: alankent/magento2devbox-web:latest
11-
volumes:
11+
12+
# Uncomment this line if you uncomment any of the following volumes.
13+
#volumes:
1214

1315
# LEAVE THIS LINE COMMENTED OUT IF YOU ARE USING UNISON.
1416
# Uncomment to use Docker volume mounts to share files with
@@ -55,20 +57,20 @@ services:
5557
ports:
5658

5759
# Pick a random unused web server port.
58-
# (Use 8080:80 for force external port to be 8080.)
59-
- 80
60+
# (Use "8080:80" for force external port to be 8080.)
61+
- "80"
6062

61-
# The SSH port.
62-
- 22
63+
# Pick a random SSH port.
64+
- "22"
6365

6466
# Pick a random unused unison port.
6567
# (Only needed if using Unison for file syncing.)
66-
- 5000
68+
- "5000"
6769

68-
# Default BrowserSync ports.
70+
# Expose the BrowserSync ports.
6971
# (Only needed if using BrowserSync for frontend development.)
70-
- 3000
71-
- 3001
72+
- "3000"
73+
- "3001"
7274

7375
db:
7476
restart: always
@@ -81,7 +83,8 @@ services:
8183
- MYSQL_ROOT_PASSWORD=root
8284
- MYSQL_DATABASE=magento2
8385

84-
volumes:
86+
# Uncomment the following line if you uncomment a volume mount
87+
#volumes:
8588

8689
# Uncomment to mount log files locally.
8790
#- "./shared/logs/mysql:/var/log/mysql"

m2ssh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
if [[ ! -f docker-compose.yml ]]; then
4+
echo "Warning: No `docker-compose.yml` file found."
5+
echo "Are you running this script from the correct directory?"
6+
exit 1
7+
fi
8+
9+
SSH_HOST=$(docker-compose port web 22 | awk -F: '{
10+
host = $1
11+
if (host == "") host = "localhost"
12+
if (host == "0.0.0.0") host = "localhost"
13+
print host
14+
}')
15+
16+
SSH_PORT=$(docker-compose port web 22 | awk -F: '{print $2}')
17+
18+
exec ssh -p ${SSH_PORT} magento2@${SSH_HOST} $*

m2ssh.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@ECHO OFF
2+
3+
REM Fetch the external Docker SSH port number
4+
FOR /f "delims=" %%A IN ('docker-compose port web 22') DO SET "CMD_OUTPUT=%%A"
5+
FOR /f "tokens=1,* delims=:" %%A IN ("%CMD_OUTPUT%") DO SET "SSH_PORT=%%B"
6+
7+
REM Run SSH
8+
ssh -p %SSH_PORT% magento2@localhost %*
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)