Skip to content

Deploy Play With Dock on a local Ubuntu 18.04 machine

peihunglin edited this page Mar 23, 2020 · 14 revisions

The official installation doc is very limited. Here is the sequence which works for me:

Warning

The default PWD installation has a fatal security flaw (users can mount host device in RW mode from the terminal), using the instructions documented by the first part of https://securityboulevard.com/2019/01/how-i-hacked-play-with-docker-and-remotely-ran-code-on-the-host/

  • As mentioned by the author of PWD, this is intentional. '''The environment in play-with-docker.com has some extra security and scalability features which are not part of the open source project. If you want to know more about enterprise pricing..''' https://github.com/play-with-docker/play-with-docker/issues/366

Prerequisite

Ubuntu 18.04 LTS

Install docker and related things

# Prepare apt repo for docker
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

sudo apt-get update

# Install docker 
 sudo apt-get install docker-ce docker-ce-cli containerd.io 

# Install docker compose: we will compose multiple docker based services

 sudo apt-get install docker-compose 

# add your ccurent account into docker group, so you don't need to use sudo to run docker commands

sudo usermod -aG docker $USER

# You may have to log out and log in again to make the group change effective. 

 docker swarm init

# If you get error from the previous command, try to run the following command and re-run the previous command.

 sudo chmod 666 /var/run/docker.sock

# Obtain the docker-in-docker image
docker pull franela/dind

Install go language

PWD is mostly written in go language. So we have to install golang.

sudo apt install go-dep golang-go 

# GOPATH is necessary to compile/run golang programs
mkdir ~/.go
export GOPATH=$HOME/.go  

vi ~/.bashrc to add "export GOPATH=$HOME/.go"

Linux kernel preparation

PWD uses overlay and xt_ipvs kernel modules to work.

sudo modprobe xt_ipvs overlay

You can add two lines into /etc/modules-load.d/modules.conf to automatically load the modules at boot time

overlay
xt_ipvs

Download PWD

git clone https://github.com/franela/play-with-docker  

The instructions on this page were tested to work with the following revision:

commit 00e5a8f9b4a01f8c723f74b2637dde5796a87869 (HEAD -> master, origin/master, origin/HEAD)
Author: Michael Irwin <mikesir87@gmail.com>
Date:   Tue Oct 22 13:05:37 2019 -0400

    Add docker-app as a cli plugin (#364)

Prepare software dependencies

We need to download dependencies for go programs used by PWD

cd play-with-docker/  

# "./..." means start in the current directory ("./") and find all packages below that directory ("...")
go get -v -d -t ./...  

# Must go to this path first for remaining commands
cd $HOME/.go/src/github.com/play-with-docker/play-with-docker

# install all dependencies for this Go project
# the PWD container is managed by a Go program
dep ensure

Start the docker services

# run composed services in background
docker-compose up -d 

# to see what is currently running
docker-compose ps 

# You should see the following entries reported by docker ps
# three services are bundled together by PWD: l2, pwd, and haproxy.
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                              NAMES
bcf60cbf2477        golang              "/bin/sh -c 'ssh-key…"   18 minutes ago      Up 18 minutes       0.0.0.0:443->443/tcp, 0.0.0.0:8022->22/tcp, 0.0.0.0:8053->53/tcp   l2
3f3bfe6f8738        golang              "/bin/sh -c 'ssh-key…"   18 minutes ago      Up 18 minutes                                                                          pwd
c5941c74ce9a        haproxy             "/docker-entrypoint.…"   18 minutes ago      Up 18 minutes       0.0.0.0:80->8080/tcp                                               haproxy

Test your installation:

  • visit localhost in your browser: you should be able to see the welcome page and start the PWD from the browser
  • the default installation is accessible from local machine only.

Using a domain name

If you want to make your PWD installation visible to the outside, you have to do two additional steps

  • setup a domain name like lab.mydomain.com and let it point to the IP address of your server running PWD
  • edit config/config.go line 58, replace PlaygroundDomain's value "localhost" with "lab.mydomain.com"

Troubleshooting

GOPATH variable is not set.

  • you may actually set it already (export GOPATH=$HOME/.go). But you may be running '''docker-compose up ''' after sudo, so the variable is lost.
  • solution: export GOPATH after sudo, or run using your own account added into docker group