Multiple Container Docker Usage

March 22, 2016 in #docker

What's wrong?

Here are some ways that you can look at what's going on with your setup.

docker logs <container_name>  
docker exec \  
   nginx-proxy cat \ 
   /etc/nginx/conf.d/default.conf

Multiple containers, one host

jwilder/nginx-proxy automatically adds routing for multiple containers. Very handy.

docker run -d -p 80:80 \  
  -v /var/run/docker.sock:/tmp/docker.sock \
  -t jwilder/nginx-proxy

Rstudio

Here's how we can quickly run an instance of RStudio

docker run -d \  
   -e VIRTUAL_HOST=rstudio.yourdomain.ccom \
   -e VIRTUAL_PORT=8787 \ 
   -e USER=admin \ 
   -e PASSWORD=password \ 
   -e ROOT=TRUE \ 
   rocker/rstudio 

Gitlab

Must bind 22 and 443 from gitlab to real ports as nginx-proxy only proxies http/https requests. On my setup I have ufw running so I typically just open a port few ports:

sudo ufw add 23  
sudo ufw add 444/tcp  

And then assign them appropriately using -p port:internalport_.

docker run --d \  
    --hostname gitlab.yourdomain.com \
    -e VIRTUAL_HOST = gitlab.yourdomain.com 
    -p 444:443 \ 
    -p 80:80 \ 
    -p 23:22 \
    -e VIRTUAL_PORT=80
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

Using Docker Compose

Using docker compose makes it so that you don't have to muck about too much with command line. Especially for longer calls (like the gitlab call above) it makes more sense to write it as a yml file than as a big messy line in the CLI.

So far, a good strategy has been to make a folder in the /home/user/ directory for each service. Within that folder, bind any volumes as well as create your comps