-
Notifications
You must be signed in to change notification settings - Fork 0
Docker Tricks
Base directory for mounting
mkdir -p ~/Projects/docker
cd ~/Projects/docker
This is for replacing some system components in my development machine. Since I use ArchLinux, that is a rolling release, sometimes I need to lock components to the app I developing, or use this machines as a radioactive components that I can just rm later. Examples:
- Rails ES gem does not yet support Elasticsearch 6, so I just use an ES 5.6 docker instance
- ArchLinux is behind versions in certain components (MariaDB 11 is not available, and I need to test some JSON goodies).
- If everything goes wrong, just remove the fucking docker instance.
- I only trust PostgreSQL as host service, not docker one, using the nice pacman packages that dont break anything :)
My dev environment changes a lot. It is easier to manage some pieces individually. If you do develop a single application at a large time span, you're better off creating composer files and running them.
Considering that $PWD is the base directory
Running Traefik as HTTP Proxy server
mkdir traefik
curl https://raw.githubusercontent.com/containous/traefik/master/traefik.sample.toml > traefik/traefik.toml
docker run -d \
--name traefik \
--publish 80:80 \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--mount type=bind,source=$PWD/traefik/traefik.toml,target=/traefik.toml \
--label traefik.port=8080 \
--label traefik.frontend.rule=Host:monitor.localhost \
traefik \
--docker \
--docker.domain=localhost \
--docker.watch \
--web
You can now use http://monitor.localhost to observe your requests.
Portainer as Docker GUI
mkdir portainer
docker run -d \
--name portainer \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
--mount type=bind,src=$PWD/portainer,dst=/data \
--label traefik.port=9000 \
portainer/portainer \
-H unix:///var/run/docker.sock
You can now use http://portainer.localhost to manage your Docker containers.
mkdir mysql
docker run -d \
--name mysql \
-p 3306:3306 \
-v $PWD/mysql:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD="MY ROOT PASSWORD" \
--memory 384000000 \
--restart unless-stopped \
mysql:5.7
Memory: Limit memory usage in bytes
It exposes port 3306 to your host computer (and potentially to your network if your host is not firewalled). Now you can install a compatible mysql client in your host OS.
For ArchLinux: pacman -S percona-server-clients or pacman -S mariadb-clients
Ghost using MySQL above
mysql -h 127.0.0.1 -uroot -p
CREATE USER 'ghost'@'%';
GRANT ALL PRIVILEGES ON ghost.* To 'ghost'@'%' IDENTIFIED BY 'ghost123';
FLUSH PRIVILEGES;
CTRL-D to disconnect
mkdir ghost
docker run -d \
--name ghost \
--mount type=bind,src=$PWD/ghost,dst=/var/lib/ghost/content \
--label traefik.port=2368 \
--link mysql:mysql \
-e database__client=mysql \
-e database__connection__host=mysql \
-e database__connection__user=ghost \
-e database__connection__password=ghost123 \
-e database__connection__database=ghost \
--restart unless-stopped \
ghost:alpine
First time setup will be available at http://ghost.localhost/ghost/ and the blog at http://ghost.localhost/
docker run --name redis -d \
-p 6379:6379 \
--memory 384000000 \
--restart unless-stopped \
redis:alpine