doc/docker.md

119 lines
2.7 KiB
Markdown
Raw Normal View History

2014-06-05 13:56:19 +02:00
# Docker and YunoHost
*Here is a small memo-documentation page on how to test/develop YunoHost with Docker.*
*Find other ways to install YunoHost **[here](/install)**.*
<img src="/images/docker.png" width=250>
2014-06-05 13:56:19 +02:00
---
## Install Docker
2015-04-12 23:12:03 +02:00
**Pre-requisite**: a x86 computer under Ubuntu 14.04 (or above), or ArchLinux.
2014-06-05 13:56:19 +02:00
2015-04-12 23:05:00 +02:00
On Ubuntu :
2014-06-05 13:56:19 +02:00
```bash
curl -s https://get.docker.io/ubuntu/ | sudo sh
```
2015-04-12 23:05:00 +02:00
On ArchLinux :
2014-06-05 13:56:19 +02:00
```bash
sudo pacman -Sy docker
```
2015-04-12 23:12:03 +02:00
**Note:** you may have to start Docker's daemon manually (as root: `service docker start`, `systemctl start docker` or simply `docker -d`)
2014-06-05 13:56:19 +02:00
---
## Build the YunoHost container
2015-04-12 23:05:00 +02:00
The following command will fetch the latest YunoHost built image:
```bash
2015-10-11 19:14:53 +02:00
docker pull zamentur/yunohost-stable8
2015-04-12 23:05:00 +02:00
```
You can also build the image manually:
2014-06-05 13:56:19 +02:00
```bash
2015-10-11 19:14:53 +02:00
docker build -t zamentur/yunohost-stable8 github.com/YunoHost/Dockerfile
2014-06-05 13:56:19 +02:00
```
You can check that the container is successfully built with the `docker images` command.
---
## Run the container
2016-01-14 16:38:22 +01:00
To start the container, run the next command by replacing DOMAIN by a valid domain e.g.: example.com => yunohost.example.com
2014-06-05 13:56:19 +02:00
```bash
2015-10-11 19:14:53 +02:00
docker run -h yunohost.DOMAIN -v $(pwd):/yunohost -d zamentur/yunohost-stable8 /sbin/init
2014-06-05 13:56:19 +02:00
```
2015-04-12 23:05:00 +02:00
If you want to run the container and forward all the interesting ports to the host:
2014-06-05 13:56:19 +02:00
2015-04-12 23:05:00 +02:00
```bash
2015-10-11 19:14:53 +02:00
docker run -d -h yunohost.DOMAIN -v $(pwd):/yunohost \
2015-04-12 23:05:00 +02:00
-p 25:25 \
-p 53:53/udp \
-p 80:80 \
-p 443:443 \
-p 465:465 \
-p 993:993 \
-p 5222:5222 \
-p 5269:5269 \
-p 5290:5290 \
2015-10-11 19:14:53 +02:00
zamentur/yunohost-stable8 \
2015-04-12 23:05:00 +02:00
/sbin/init
```
2014-06-05 13:56:19 +02:00
2015-04-12 23:05:00 +02:00
You can find more information on these steps on the Docker's documentation:
2015-02-04 11:32:19 +01:00
* http://docs.docker.com/reference/commandline/cli/#run
* http://docs.docker.com/userguide/dockerlinks/
2014-06-05 13:56:19 +02:00
---
2015-04-12 23:05:00 +02:00
## Post-installation
2015-10-11 19:14:53 +02:00
Go in the container by replacing XXXX by the id obtained when `docker run`
2015-04-12 23:05:00 +02:00
```bash
2015-10-11 19:14:53 +02:00
docker exec -t -i XXXX /bin/bash
```
Next run postinstall with the dedicated script to docker
```bash
postinstall
2015-04-12 23:05:00 +02:00
```
---
## Useful commands
2014-06-05 13:56:19 +02:00
2015-10-11 19:14:53 +02:00
Find your container's IP address (should looks like 172.17.0.x)
```bash
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER_ID>
```
2015-04-12 23:05:00 +02:00
Snapshot container's state
2014-06-05 13:56:19 +02:00
```bash
2015-10-11 19:14:53 +02:00
docker commit <container_ID> zamentur/yunohost-stable8:tag
# E.g.: docker commit 3e85317430db zamentur/yunohost-stable8:03052014
2014-06-05 13:56:19 +02:00
```
2015-04-12 23:05:00 +02:00
Assign an IP to a container
2014-06-05 13:56:19 +02:00
```bash
# You will need iptables, and to activate IP forwarding on your system
iptables -t nat -A PREROUTING -d <IP.to.assign> -j DNAT --to-destination <container.IP>
iptables -t nat -A POSTROUTING -s '<container.IP>/32' -o eth0 -j SNAT --to-source <IP.to.assign>
# Be careful on the network interface (here eth0)
```
2015-04-12 23:05:00 +02:00
Log in a YunoHost running container
2014-06-05 13:56:19 +02:00
```bash
2015-02-04 11:32:19 +01:00
# Otherwise, with docker
2015-04-12 23:05:00 +02:00
docker exec -t -i <container_ID> /bin/bash
2014-06-05 13:56:19 +02:00
```