digitaloceandocker.md 3.12 KB
Newer Older
1 2
# Digital Ocean and Docker Machine test environment

3 4 5
CAUTION: **Caution:**
This guide is for quickly testing different versions of GitLab and not recommended for ease of
future upgrades or keeping the data you create.
6 7 8 9 10 11 12 13 14 15

## Initial setup

In this guide you'll configure a Digital Ocean droplet and set up Docker
locally on either macOS or Linux.

### On macOS

#### Install Docker Toolbox

16
- <https://www.docker.com/products/docker-toolbox>
17 18 19 20 21

### On Linux

#### Install Docker Engine

22
- <https://docs.docker.com/engine/installation/linux/>
23 24 25

#### Install Docker Machine

26
- <https://docs.docker.com/machine/install-machine/>
27

28 29
NOTE: **Note:**
The rest of the steps are identical for macOS and Linux.
30 31 32

### Create new docker host

33 34
1. Login to Digital Ocean.
1. Generate a new API token at <https://cloud.digitalocean.com/settings/api/tokens>.
35

36
    This command will create a new DO droplet called `gitlab-test-env-do` that will act as a docker host.
37

38 39
    NOTE: **Note:**
    4GB is the minimum requirement for a Docker host that will run more than one GitLab instance.
40

41 42 43
    - RAM: 4GB
    - Name: `gitlab-test-env-do`
    - Driver: `digitalocean`
44

45
1. Set the DO token:
46

47 48 49
    ```sh
    export DOTOKEN=<your generated token>
    ```
50

51
1. Create the machine:
52

53 54 55 56 57 58 59
    ```sh
    docker-machine create \
      --driver digitalocean \
      --digitalocean-access-token=$DOTOKEN \
      --digitalocean-size "4gb" \
        gitlab-test-env-do
    ```
60

61
Resource: <https://docs.docker.com/machine/drivers/digital-ocean/>.
62 63 64 65 66 67 68 69 70

### Creating GitLab test instance

#### Connect your shell to the new machine

In this example we'll create a GitLab EE 8.10.8 instance.

First connect the docker client to the docker host you created previously.

71
```sh
72 73 74 75 76 77 78
eval "$(docker-machine env gitlab-test-env-do)"
```

You can add this to your `~/.bash_profile` file to ensure the `docker` client uses the `gitlab-test-env-do` docker host

#### Create new GitLab container

79 80 81 82 83 84
- HTTP port: `8888`
- SSH port: `2222`
  - Set `gitlab_shell_ssh_port` using `--env GITLAB_OMNIBUS_CONFIG`
- Hostname: IP of docker host
- Container name: `gitlab-test-8.10`
- GitLab version: **EE** `8.10.8-ee.0`
85

86
##### Set up container settings
87

88
```sh
89 90 91 92 93 94
export SSH_PORT=2222
export HTTP_PORT=8888
export VERSION=8.10.8-ee.0
export NAME=gitlab-test-8.10
```

95 96 97
##### Create container

```sh
98 99 100 101 102 103 104 105 106 107 108 109
docker run --detach \
--env GITLAB_OMNIBUS_CONFIG="external_url 'http://$(docker-machine ip gitlab-test-env-do):$HTTP_PORT'; gitlab_rails['gitlab_shell_ssh_port'] = $SSH_PORT;" \
--hostname $(docker-machine ip gitlab-test-env-do) \
-p $HTTP_PORT:$HTTP_PORT -p $SSH_PORT:22 \
--name $NAME \
gitlab/gitlab-ee:$VERSION
```

#### Connect to the GitLab container

##### Retrieve the docker host IP

110
```sh
111 112 113 114
docker-machine ip gitlab-test-env-do
# example output: 192.168.151.134
```

115
Browse to: <http://192.168.151.134:8888/>.
116 117 118

##### Execute interactive shell/edit configuration

119
```sh
120 121 122
docker exec -it $NAME /bin/bash
```

123
```sh
124 125 126 127 128 129 130
# example commands
root@192:/# vi /etc/gitlab/gitlab.rb
root@192:/# gitlab-ctl reconfigure
```

#### Resources

131 132 133
- <https://docs.gitlab.com/omnibus/docker/>.
- <https://docs.docker.com/machine/get-started/>.
- <https://docs.docker.com/machine/reference/ip/>.