Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

Commit 415a110

Browse files
committed
Issue #1206: Allow initial docker bake build to use custom IP.
1 parent 36cc68b commit 415a110

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

docs/other/docker.md

+17-10
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@ Drupal VM includes a few `composer` scripts and an example `docker-compose.yml`
44

55
> **Docker support is currently experimental**, so you may want to wait until Docker support is more finalized unless you're already familiar with Docker, and okay with potentially backwards-incompatible changes when upgrading Drupal VM.
66
7+
## Managing your hosts file
8+
9+
Before using Docker to run Drupal VM, you should [edit your hosts file](https://support.rackspace.com/how-to/modify-your-hosts-file/) and add the following line:
10+
11+
192.168.88.88 drupalvm.dev
12+
13+
...but substituting the IP address and domain name you'd like to use to access your Drupal VM container.
14+
15+
> If you're using Docker for Mac, you need to perform one additional step to ensure you can access Drupal VM using a unique IP address:
16+
>
17+
> 1. Add an alias IP address on the loopback interface: `sudo ifconfig lo0 alias 192.168.88.88/24`
18+
>
19+
> Note that you'll have to create the alias again after restarting your computer. See [this Docker (moby) issue](https://github.com/moby/moby/issues/22753#issuecomment-246054946) for more details.
20+
721
## Building ('baking') a Docker container with Drupal VM
822

923
After you've configured your Drupal VM settings in `config.yml` and other configuration files, run the following command to create and provision a new Docker container:
1024

11-
composer docker-bake
25+
[OPTIONS] composer docker-bake
26+
27+
Look at the variables defined in the `provisioning/docker/bake.sh` file for all the currently-available options (e.g. `DRUPALVM_IP_ADDRESS`, `DISTRO`, etc.). You can use Drupal VM's defaults by running the `composer docker-bake` command without any options.
1228

1329
This process can take some time (it should take a similar amount of time as it takes to build Drupal VM normally, using Vagrant and VirtualBox), and at the end, you should see a message like:
1430

@@ -51,12 +67,3 @@ Drupal VM includes an `example.docker-compose.yml` file. To use the file, copy i
5167
docker-compose up -d
5268

5369
(The `-d` tells `docker-compose` to start the containers and run in the background.) You can stop the containers with `docker-compose stop`, or remove all their configuration with `docker-compose down`.
54-
55-
> If you're using Docker for Mac, you need to perform two manual steps prior to running `docker-compose up` to ensure you can access Drupal VM using a unique IP address:
56-
>
57-
> 1. Run `sudo nano /etc/hosts` and add a line for Drupal VM in Docker (e.g. `192.168.88.88 drupalvm.dev` using the defaults).
58-
> 2. Add an alias IP address on the loopback interface: `sudo ifconfig lo0 alias 192.168.88.88/24`
59-
>
60-
> Note that you'll have to create the alias again after restarting your computer. And if you don't know what any of this means, you might want to hold off on running Drupal VM inside Docker for now :)
61-
>
62-
> See [this Docker (moby) issue](https://github.com/moby/moby/issues/22753#issuecomment-246054946) for more details.

provisioning/docker/bake.sh

+17-14
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
set -e
77

88
# Set variables.
9+
DRUPALVM_IP_ADDRESS="${DRUPALVM_IP_ADDRESS:-192.168.88.88}"
910
DRUPALVM_MACHINE_NAME="${DRUPALVM_MACHINE_NAME:-drupal-vm}"
1011
DRUPALVM_HOSTNAME="${DRUPALVM_HOSTNAME:-localhost}"
1112
DRUPALVM_PROJECT_ROOT="${DRUPALVM_PROJECT_ROOT:-/var/www/drupalvm}"
1213

13-
HOST_HTTP_PORT="${HOST_HTTP_PORT:-8080}"
14-
HOST_HTTPS_PORT="${HOST_HTTPS_PORT:-8443}"
14+
DRUPALVM_HTTP_PORT="${DRUPALVM_HTTP_PORT:-80}"
15+
DRUPALVM_HTTPS_PORT="${DRUPALVM_HTTPS_PORT:-443}"
1516

1617
DISTRO="${DISTRO:-ubuntu1604}"
1718
OPTS="${OPTS:---privileged}"
1819
INIT="${INIT:-/lib/systemd/systemd}"
1920

20-
# Pretty colors.
21-
red='\033[0;31m'
22-
green='\033[0;32m'
23-
neutral='\033[0m'
21+
# Helper function to colorize statuses.
22+
function status() {
23+
status=$1
24+
printf "\n"
25+
echo -e -n "\033[32m$status"
26+
echo -e '\033[0m'
27+
}
2428

2529
# Set volume options.
2630
if [[ "$OSTYPE" == "darwin"* ]]; then
@@ -30,12 +34,12 @@ else
3034
fi
3135

3236
# Run the container.
33-
printf "\n"${green}"Bringing up Docker container..."${neutral}"\n"
37+
status "Bringing up Docker container..."
3438
docker run --name=$DRUPALVM_MACHINE_NAME -d \
3539
--add-host "$DRUPALVM_HOSTNAME drupalvm":127.0.0.1 \
3640
-v $PWD:$DRUPALVM_PROJECT_ROOT/:$volume_opts \
37-
-p $HOST_HTTP_PORT:80 \
38-
-p $HOST_HTTPS_PORT:443 \
41+
-p $DRUPALVM_IP_ADDRESS:$DRUPALVM_HTTP_PORT:80 \
42+
-p $DRUPALVM_IP_ADDRESS:$DRUPALVM_HTTPS_PORT:443 \
3943
$OPTS \
4044
geerlingguy/docker-$DISTRO-ansible:latest \
4145
$INIT
@@ -44,14 +48,13 @@ docker run --name=$DRUPALVM_MACHINE_NAME -d \
4448
docker exec $DRUPALVM_MACHINE_NAME mkdir -p $DRUPALVM_PROJECT_ROOT/drupal
4549

4650
# Set things up and run the Ansible playbook.
47-
printf "\n"${green}"Running setup playbook..."${neutral}"\n"
51+
status "Running setup playbook..."
4852
docker exec --tty $DRUPALVM_MACHINE_NAME env TERM=xterm \
4953
ansible-playbook $DRUPALVM_PROJECT_ROOT/tests/test-setup.yml
5054

51-
printf "\n"${green}"Provisioning Drupal VM inside Docker container..."${neutral}"\n"
55+
status "Provisioning Drupal VM inside Docker container..."
5256
docker exec $DRUPALVM_MACHINE_NAME env TERM=xterm ANSIBLE_FORCE_COLOR=true \
5357
ansible-playbook $DRUPALVM_PROJECT_ROOT/provisioning/playbook.yml
5458

55-
printf "\n"${green}"...done!"${neutral}"\n"
56-
57-
printf "\n"${green}"Visit the Drupal VM dashboard: http://localhost:$HOST_HTTP_PORT"${neutral}"\n"
59+
status "...done!"
60+
status "Visit the Drupal VM dashboard: http://$DRUPALVM_IP_ADDRESS:$DRUPALVM_HTTP_PORT"

0 commit comments

Comments
 (0)